René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
SWFMovie [Ming wrapper class] | ||
Every movie that is created with Ming wrapper needs at least this class.
A flash movie is in many respects very similar to a MovieClip (Sprite). Therefore, this class is inherited from
MovieClip_ which defines the common functionality.
Selected methodsExport
A MovieClip and a Font can be given a linkage ID and be exported. This feature is
handled through the Export method.
Such an exported MovieClip (and Font?) can then be referenced with the Action Script function
attachMovie like so:
_root.attachMovie('linkage_id', 'instance_name', x)
See Sparks example for more details.
The codeSWFMovie.h
#ifndef SWFMOVIE_H #define SWFMOVIE_H #include "MovieClip_.h" #include "MovieClip.h" #include "Gradient.h" std::string ntos (int); std::string ntos (float); class Movie : public MovieClip_ { public: Movie(std::string const& name, float width, float height, float rate=12, int version = 6); virtual ~Movie(); using MovieClip_::Add; virtual void Add (Action const&); virtual DisplayItem Add (Character_ &); virtual DisplayClip Add (MovieClip &); virtual void Stop (); virtual void NextFrame() const; virtual void Remove (DisplayItem item); void BackgroundColor(byte r, byte g, byte b); virtual void Frames (int); virtual void Label (std::string const& name); void Export (MovieClip const&, std::string const& linkage_id); void Export (Font const&, std::string const& linkage_id); private: SWFMovie movie_; std::string filename_; }; #endif SWFMovie.cpp
#include "SWFMovie.h" #include <sstream> std::string ntos(int i) { std::stringstream s; s<<i; return s.str(); } std::string ntos(float f) { std::stringstream s; s<<f; return s.str(); } // TODO: MUST somehow be defined, linker error // Copied from src/blocks/method.c void fileOutputMethod(byte b, void *data) { FILE *f = (FILE *)data; fputc(b, f); } Movie::Movie(std::string const& filename, float width, float height, float rate, int version) { Ming_useSWFVersion(version); movie_ = newSWFMovieWithVersion(version); SWFMovie_setRate (movie_, rate ); SWFMovie_setDimension (movie_, width, height); Frames(1); filename_ = filename; } Movie::~Movie() { FILE* f; f = fopen(filename_.c_str(), "wb"); SWFMovie_output(movie_, (SWFByteOutputMethod) fileOutputMethod, f); destroySWFMovie(movie_); } void Movie::BackgroundColor(byte r, byte g, byte b) { SWFMovie_setBackground(movie_, r, g, b); } void Movie::Add(Action const& a) { SWFMovie_add(movie_, a.swf_block()); } DisplayItem Movie::Add(Character_ & c) { c.BeforeAdding(); DisplayItem d(SWFMovie_add(movie_, c.swf_block())); c.AfterAdding(d); return d; } DisplayClip Movie::Add(MovieClip & mc) { mc.BeforeAdding(); DisplayClip d(SWFMovie_add(movie_, mc.swf_block())); mc.AfterAdding(d); return d; } void Movie::Stop() { Action stop("stop();"); Add(stop); } void Movie::NextFrame() const { SWFMovie_nextFrame(movie_); } void Movie::Remove(DisplayItem item) { SWFMovie_remove(movie_, item.item_); } void Movie::Frames(int nofFrames) { SWFMovie_setNumberOfFrames(movie_, nofFrames); } void Movie::Label(const std::string& label) { SWFMovie_labelFrame(movie_, label.c_str()); } void Movie::Export(MovieClip const& mc, std::string const& linkage_id) { SWFMovie_addExport(movie_, mc.swf_block(), linkage_id.c_str()); } |