2 var FlappMovieClip = function(parentMovieClip, name, matrix, colorTransform) {
3 this.OBJECT_TYPE = 2; // 1:Shape, 2: MovieClip
4 this.parentMovieClip = parentMovieClip?parentMovieCli:null;
5 this.rootMovieClip = parentMovieClip?parentMovieClip.rootMovieClip:this;
6 this.name = name?name:'anonymous';
8 this.colorTransform = colorTransform;
9 this.childMovieClips = {}; // name => movieClip
10 this.childMovieClips_seqnum = 1; // for name movieClip
11 this.clearControlTags();
13 this.prevShowFramePos = 0;
15 canvas = document.createElement('canvas');
16 canvas.width = 240; // XXX
17 canvas.height = 240; // XXX
19 this.canvasDirty = false; // dirtyFlag
21 this.displayList = new FlappDisplay();
24 this.currentFrame = 0;
28 var actionVarriableTable = {};
29 var actionVarriablOrigKeys = {};
31 FlappMovieClip.prototype = {
32 clearControlTags: function(controlTag) {
33 this.controlTagsList = [[]]; //
34 this.actionTagsList = [[]];
35 this.labelMap = {}; // label => frameNum
36 this.framesLoaded = 0;
38 appendControlTag: function(controlTag) {
39 // console.debug("FlappMovieClip::appendControlTag");
40 if (controlTag.code === 12) { // DoAction
41 this.actionTagsList[this.framesLoaded].push(controlTag);
44 this.controlTagsList[this.framesLoaded].push(controlTag);
45 if (controlTag.code === 1) { // ShowFrame
46 this.controlTagsList.push([]);
47 this.actionTagsList.push([]);
49 } else if (controlTag.code === 43) { // FrameLabel
50 this.labelMap[controlTag.name] = this.framesLoaded;
53 setControlTags: function(controlTags) {
54 this.clearControlTags();
55 for (var i = 0, l = controlTags.length ; i < l ; i++) {
56 this.appendControlTag(controlTags[i]);
59 addChildMovieClip: function(name, movieClip) {
60 this.childMovieClips[name] = movieClip;
62 deleteChildMovieClip: function(name) {
63 delete this.childMovieClips[name];
65 control: function(dict) {
66 if (this.totalframes === 0) { // imcomplete
69 console.debug("FlappMovieClip::control");
70 if (this.framesLoaderd < this.totalframes) { // imcomplete
71 if (this.currentFrame < this.framesLoaderd) {
75 for (var mc in this.childMovieClips) {
76 this.childMovieClips[mc].control(dict);
79 this.controlThis(dict);
83 controlThis: function(dict) {
84 console.debug("FlappMovieClip::controlThis");
87 if ((this.currentFrame < 0 ) || (this.totalframes <= this.currentFrame)) {
88 this.currentFrame = 0;
90 var controlTags = this.controlTagsList[this.currentFrame];
92 for (i = 0, l = controlTags.length ; i < l ; i++) {
97 case 26: // PlaceObject2
100 if (tag.id === null) {
103 defineTag = dict.get(tag.id);
105 if (defineTag === undefined) {
109 if (defineTag.code === 39) { // DefineSprite
112 name = "instance"+this.childMovieClips_seqnum;
113 defineTag.name = name;
114 this.childMovieClips_seqnum++;
116 var obj = FlappMovieClip(this, name, tag.matrix, tag.colorTransform);
117 obj.setControlTags(defineTag.controlTags);
118 this.addChildMovieClip(name, obj);
119 } else if (defineTag.code === 2) { // DefineShape
120 var obj = FlappShape(name, tag.matrix, tag.colorTransform);
121 obj.loadShapeTag(defineTag);
123 this.displayList.set(tag.depth, obj, tag);
129 for (var mc in this.childMovieClips) {
130 this.childMovieClips[mc].action();
137 actionThis: function() {
138 var actionTags = this.actionTagsList[this.currentFrame];
139 var l = actionTags.length;
140 console.debug("FlappMovieClip::actionThis: actionTags.length:"+l);
141 for (var i = 0 ; i < l ; i++) {
142 var tag = actionTags[i];
143 var movieClip = this;
144 FlappAction.exec(tag, movieClip, this.rootMovieClip);
147 increment: function() {
148 for (var mc in this.childMovieClips) {
149 this.childMovieClips[mc].increment();
152 this.incrementThis();
155 incrementThis: function() {
156 console.debug("FlappMovieClip::incrementThis: "+this.currentFrame);
158 if (this.totalframes <= this.currentFrame) {
160 this.currentFrame = 0; // play
162 this.playing = false;
165 if (this.totalframes === 1) {
166 this.playing = false;
169 render: function(canvas) {
170 var depthList = this.displayList.sortedDepth().reverse();
171 for (var i = 0, l = depthList.length ; i < l ; i++) {
172 var depth = depthList[i];
173 var obj = this.display.get(depth);
174 if (obj.OBJECT_TYPE === 2) { // MovieClip
175 for (var movieClip in this.childMovieClips) {
176 childMovieClips.render(this.canvas);
178 obj.render(this.canvas);
179 } else if ((obj.OBJECT_TYPE === 2) && (this.playing == true)) {
180 obj.render(this.canvas);
184 setVariable: function(key, value) {
185 var lcKey = key.toLowerCase();
186 actionVarriableTable[lcKey] = value;
187 actionVarriablOrigKeys[lcKey] = key;
189 getVariable: function(key) {
190 var lcKey = key.toLowerCase();
191 if (lcKey in actionVarriableTable) {
192 return actionVarriableTable[lcKey];
196 gotoFrame: function(frameNum) {
197 console.debug("FlappMovieClip::gotoFrame"+frameNum);
198 this.currentFrame = frameNum;
200 gotoLabel: function(frameLabel) {
201 frameNum = labelMap[frameLabel];
202 console.debug("FlappMovieClip::gotoFrame"+frameLabel+"=>"+frameNum);
203 this.currentFrame = frameNum;
209 this.playing = false;
211 destroy: function() { // destructor
212 for (name in this.childMovieClips) {
213 this.childMovieClips[name].destroy();
215 this.parentMovieClip = null;
216 this.rootMovieClip = null;
217 this.controlTagsList = null;
218 this.actionTagsList = null;
219 this.labelMap = null;
221 this.displayList = null;
224 global.FlappMovieClip = FlappMovieClip;