1 goog.provide('FlappMovieClip');
2 goog.require('FlappObject');
3 goog.require('FlappDisplay');
4 goog.require('FlappShape');
5 goog.require('FlappAction');
6 goog.require('FlappCanvas');
8 goog.scope(function() {
13 FlappMovieClip = function(parentMovieClip, matrix, colorTransform) {
14 this.OBJECT_TYPE = 2; // 1:Shape, 2:MovieClip
15 this.parentMovieClip = parentMovieClip?parentMovieClip:null;
16 this.rootMovieClip = parentMovieClip?parentMovieClip.rootMovieClip:this;
18 this.setMatrix(matrix);
19 this.colorTransform = colorTransform;
20 this.childMovieClips = {}; // name => movieClip
21 this.instanceSeqno = 1; // for name object (movieClip, etc...)
22 this.clearControlTags();
24 this.prevShowFramePos = 0;
26 var canvas = document.createElement('canvas');
27 canvas.width = 240; // XXX
28 canvas.height = 240; // XXX
29 this.canvas = new FlappCanvas(canvas);
30 this.canvasDirty = false; // dirtyFlag
32 this.displayList = new FlappDisplay();
33 this.displayObjectLifeSpan = {}; // for gotoFrame
36 this.currentFrame = 0;
40 this.actionVarriableTable = {};
41 this.actionVarriablOrigKeys = {};
44 FlappMovieClip.prototype = {
45 setMatrix: function(matrix) {
47 this.absoluteMatrix = this.parentMovieClip?(matrix?FlappSWFMatrix.multiply(this.parentMovieClip.absoluteMatrix, matrix):this.parentMovieClip.absoluteMatrix):matrix;
49 clearControlTags: function() {
50 this.controlTagsList = [[]]; //
51 this.actionTagsList = [[]];
52 this.labelMap = {}; // label => frameNum
53 this.framesLoaded = 0;
55 appendControlTag: function(controlTag) {
56 // console.debug("FlappMovieClip::appendControlTag");
57 if (controlTag.code === 12) { // DoAction
58 this.actionTagsList[this.framesLoaded].push(controlTag);
61 this.controlTagsList[this.framesLoaded].push(controlTag);
62 if (controlTag.code === 1) { // ShowFrame
63 this.controlTagsList.push([]);
64 this.actionTagsList.push([]);
66 } else if (controlTag.code === 43) { // FrameLabel
67 this.labelMap[controlTag.name] = this.framesLoaded;
70 setControlTags: function(controlTags) {
71 this.clearControlTags();
72 for (var i = 0, l = controlTags.length ; i < l ; i++) {
73 this.appendControlTag(controlTags[i]);
76 addChildMovieClip: function(name, movieClip) {
77 this.childMovieClips[name] = movieClip;
79 deleteChildMovieClip: function(name) {
80 delete this.childMovieClips[name];
82 control: function(dict) {
83 if (this.totalframes === 0) { // imcomplete
86 console.debug("FlappMovieClip::control: name:"+this.name+" playing:"+this.playing);
87 if (this.framesLoaded < this.totalframes) { // imcomplete
88 if (this.currentFrame < this.framesLoaded) {
89 console.debug("control:imcomplete (currentFrame:"+this.currentFrame+" < framesLoaded:"+this.framesLoaded+")");
93 for (var mc in this.childMovieClips) {
94 this.childMovieClips[mc].control(dict);
97 this.controlThis(dict);
101 controlThis: function(dict) {
102 console.debug("FlappMovieClip::controlThis: name:"+this.name);
105 if ((this.currentFrame < 0 ) || (this.totalframes <= this.currentFrame)) {
106 this.currentFrame = 0;
108 var controlTags = this.controlTagsList[this.currentFrame];
110 for (i = 0, l = controlTags.length ; i < l ; i++) {
111 tag = controlTags[i];
115 case 26: // PlaceObject2
118 if (tag.move && (tag.id === null)) {
119 this.displayList.move(tag.depth, tag);
122 obj = this.displayList.get(tag.depth);
124 console.error("Can't get DisplayObject by depth:"+tag.depth);
126 if (obj.code === 39) { // DefineSprite
127 this.deleteChildMovieClip(obj.name);
129 this.displayList.del(tag.depth);
131 defineTag = dict.get(tag.id);
132 if (defineTag === null) {
133 console.error("defineTag === undefined");
137 if ((name === null) && (defineTag.code === 39)) {
138 name = "instance"+this.instanceSeqno;
140 this.instanceSeqno++;
142 obj = FlappObject.factory(this, name, defineTag, tag,
144 // console.debug(obj);
145 if (defineTag.code === 39) { // DefineSprite
146 obj.totalframes = defineTag.count;
148 this.addChildMovieClip(name, obj);
150 this.displayList.set(tag.depth, obj, tag);
157 for (var mc in this.childMovieClips) {
158 this.childMovieClips[mc].action();
165 actionThis: function() {
166 var actionTags = this.actionTagsList[this.currentFrame];
167 var l = actionTags.length;
168 console.debug("FlappMovieClip::actionThis: actionTags.length:"+l);
169 for (var i = 0 ; i < l ; i++) {
170 var tag = actionTags[i];
171 var movieClip = this;
172 FlappAction.exec(tag, movieClip, this.rootMovieClip);
175 increment: function() {
176 for (var mc in this.childMovieClips) {
177 this.childMovieClips[mc].increment();
180 this.incrementThis();
183 incrementThis: function() {
184 console.debug("FlappMovieClip::incrementThis: "+this.currentFrame);
186 if (this.totalframes <= this.currentFrame) {
188 this.currentFrame = 0; // play
190 this.playing = false;
193 if (this.totalframes === 1) {
194 this.playing = false;
197 render: function(canvas, dict) {
198 console.debug("FlappMovieClip::render: name:"+this.name);
199 var depthList = this.displayList.descSortedDepth();
200 for (var i = 0, l = depthList.length ; i < l ; i++) {
201 var depth = depthList[i];
202 var obj = this.displayList.get(depth);
204 // obj.render(this.canvas);
205 obj.render(canvas, dict);
208 setVariable: function(key, value) {
209 var lcKey = key.toLowerCase();
210 this.actionVarriableTable[lcKey] = value;
211 this.actionVarriablOrigKeys[lcKey] = key;
213 getVariable: function(key) {
214 var lcKey = key.toLowerCase();
215 if (lcKey in this.actionVarriableTable) {
216 return this.actionVarriableTable[lcKey];
220 gotoFrame: function(frameNum) {
221 console.debug("FlappMovieClip::gotoFrame"+frameNum);
222 this.currentFrame = frameNum;
224 gotoLabel: function(frameLabel) {
225 var frameNum = this.labelMap[frameLabel];
226 console.debug("FlappMovieClip::gotoFrame"+frameLabel+"=>"+frameNum);
227 this.currentFrame = frameNum;
233 this.playing = false;
235 destroy: function() { // destructor
236 for (var name in this.childMovieClips) {
237 this.childMovieClips[name].destroy();
239 this.parentMovieClip = null;
240 this.rootMovieClip = null;
241 this.controlTagsList = null;
242 this.actionTagsList = null;
243 this.labelMap = null;
245 this.displayList = null;