1 goog.provide('FlappMovieClip');
2 goog.require('FlappDisplay');
3 goog.require('FlappShape');
4 goog.require('FlappAction');
6 goog.scope(function() {
11 FlappMovieClip = function(parentMovieClip, name, matrix, colorTransform) {
12 this.OBJECT_TYPE = 2; // 1:Shape, 2: MovieClip
13 this.parentMovieClip = parentMovieClip?parentMovieClip:null;
14 this.rootMovieClip = parentMovieClip?parentMovieClip.rootMovieClip:this;
15 this.name = name?name:'anonymous';
17 this.colorTransform = colorTransform;
18 this.childMovieClips = {}; // name => movieClip
19 this.childMovieClips_seqnum = 1; // for name movieClip
20 this.clearControlTags();
22 this.prevShowFramePos = 0;
24 var canvas = document.createElement('canvas');
25 canvas.width = 240; // XXX
26 canvas.height = 240; // XXX
28 this.canvasDirty = false; // dirtyFlag
30 this.displayList = new FlappDisplay();
33 this.currentFrame = 0;
37 this.actionVarriableTable = {};
38 this.actionVarriablOrigKeys = {};
41 FlappMovieClip.prototype = {
42 clearControlTags: function(controlTag) {
43 this.controlTagsList = [[]]; //
44 this.actionTagsList = [[]];
45 this.labelMap = {}; // label => frameNum
46 this.framesLoaded = 0;
48 appendControlTag: function(controlTag) {
49 // console.debug("FlappMovieClip::appendControlTag");
50 if (controlTag.code === 12) { // DoAction
51 this.actionTagsList[this.framesLoaded].push(controlTag);
54 this.controlTagsList[this.framesLoaded].push(controlTag);
55 if (controlTag.code === 1) { // ShowFrame
56 this.controlTagsList.push([]);
57 this.actionTagsList.push([]);
59 } else if (controlTag.code === 43) { // FrameLabel
60 this.labelMap[controlTag.name] = this.framesLoaded;
63 setControlTags: function(controlTags) {
64 this.clearControlTags();
65 for (var i = 0, l = controlTags.length ; i < l ; i++) {
66 this.appendControlTag(controlTags[i]);
69 addChildMovieClip: function(name, movieClip) {
70 this.childMovieClips[name] = movieClip;
72 deleteChildMovieClip: function(name) {
73 delete this.childMovieClips[name];
75 control: function(dict) {
76 if (this.totalframes === 0) { // imcomplete
79 console.debug("FlappMovieClip::control");
80 if (this.framesLoaderd < this.totalframes) { // imcomplete
81 if (this.currentFrame < this.framesLoaderd) {
85 for (var mc in this.childMovieClips) {
86 this.childMovieClips[mc].control(dict);
89 this.controlThis(dict);
93 controlThis: function(dict) {
94 console.debug("FlappMovieClip::controlThis");
97 if ((this.currentFrame < 0 ) || (this.totalframes <= this.currentFrame)) {
98 this.currentFrame = 0;
100 var controlTags = this.controlTagsList[this.currentFrame];
102 for (i = 0, l = controlTags.length ; i < l ; i++) {
103 tag = controlTags[i];
107 case 26: // PlaceObject2
111 this.displayList.set(tag.depth, obj, tag);
113 defineTag = dict.get(tag.id);
115 if (defineTag.code === 39) { // DefineSprite
118 name = "instance"+this.childMovieClips_seqnum;
119 defineTag.name = name;
120 this.childMovieClips_seqnum++;
122 var obj = FlappMovieClip(this, name, tag.matrix, tag.colorTransform);
123 obj.setControlTags(defineTag.controlTags);
124 this.addChildMovieClip(name, obj);
125 } else if (defineTag.code === 2) { // DefineShape
126 var obj = new FlappShape(name, tag.matrix, tag.colorTransform);
128 obj.loadShapeTag(defineTag);
130 this.displayList.set(tag.depth, obj, tag);
137 for (var mc in this.childMovieClips) {
138 this.childMovieClips[mc].action();
145 actionThis: function() {
146 var actionTags = this.actionTagsList[this.currentFrame];
147 var l = actionTags.length;
148 console.debug("FlappMovieClip::actionThis: actionTags.length:"+l);
149 for (var i = 0 ; i < l ; i++) {
150 var tag = actionTags[i];
151 var movieClip = this;
152 FlappAction.exec(tag, movieClip, this.rootMovieClip);
155 increment: function() {
156 for (var mc in this.childMovieClips) {
157 this.childMovieClips[mc].increment();
160 this.incrementThis();
163 incrementThis: function() {
164 console.debug("FlappMovieClip::incrementThis: "+this.currentFrame);
166 if (this.totalframes <= this.currentFrame) {
168 this.currentFrame = 0; // play
170 this.playing = false;
173 if (this.totalframes === 1) {
174 this.playing = false;
177 render: function(canvas) {
178 var depthList = this.displayList.descSortedDepth();
179 for (var i = 0, l = depthList.length ; i < l ; i++) {
180 var depth = depthList[i];
181 var obj = this.displayList.getObj(depth);
182 if (obj.OBJECT_TYPE === 2) { // MovieClip
183 obj.render(this.canvas);
184 } else if ((obj.OBJECT_TYPE === 2) && (this.playing == true)) {
185 obj.render(this.canvas);
189 setVariable: function(key, value) {
190 var lcKey = key.toLowerCase();
191 this.actionVarriableTable[lcKey] = value;
192 this.actionVarriablOrigKeys[lcKey] = key;
194 getVariable: function(key) {
195 var lcKey = key.toLowerCase();
196 if (lcKey in this.actionVarriableTable) {
197 return this.actionVarriableTable[lcKey];
201 gotoFrame: function(frameNum) {
202 console.debug("FlappMovieClip::gotoFrame"+frameNum);
203 this.currentFrame = frameNum;
205 gotoLabel: function(frameLabel) {
206 var frameNum = this.labelMap[frameLabel];
207 console.debug("FlappMovieClip::gotoFrame"+frameLabel+"=>"+frameNum);
208 this.currentFrame = frameNum;
214 this.playing = false;
216 destroy: function() { // destructor
217 for (var name in this.childMovieClips) {
218 this.childMovieClips[name].destroy();
220 this.parentMovieClip = null;
221 this.rootMovieClip = null;
222 this.controlTagsList = null;
223 this.actionTagsList = null;
224 this.labelMap = null;
226 this.displayList = null;