this.canvas = document.getElementById(canvas_id);
global.flapp = this; // debug
this.header = null
- this.frameTick = 0.1; // default
+// this.frameTick = 1000 / 10; // default 0.1[sec]
+ this.frameTick = 1000; // default
};
Flapp.prototype = {
play: function() {
this.run(this.dict, this.movieClip, this.canvas);
},
setHeader: function(header) {
- this.frameTick = 1000 / header.framerate;
+// this.frameTick = 1000 / header.framerate;
+ this.frameTick = 1000;
this.movieClip.totalframes = header.framecount;
},
run: function(dict, movieClip, canvas) {
console.debug("Flapp::run");
var flapp = this;
this.canvas = canvas;
- this.matrix = FlappSWFMatrix.identity();
this.tick(flapp, this.dict, this.movieClip);
},
tick: function(flapp, dict, movieClip) {
- console.debug("Flapp::tick");
-// setTimeout(flapp.tick, flapp.frameTick, flapp, dict, movieClip);
+ console.debug("Flapp::tick "+movieClip.currentFrame);
+ setTimeout(flapp.tick, flapp.frameTick, flapp, dict, movieClip);
if (movieClip.control(dict)) {
movieClip.action();
- movieClip.render(flapp.canvas, flapp.matrix);
+ movieClip.render(flapp.canvas);
+ movieClip.increment();
}
}
};
(function(global) {
- var FlappMovieClip = function(parentMovieClip) {
+ var FlappMovieClip = function(parentMovieClip, name, matrix, colorTransform) {
this.parentMovieClip = parentMovieClip?parentMovieCli:this;
this.rootMovieClip = parentMovieClip?parentMovieClip.rootMovieClip:this;
+ this.name = name?name:'';
+ this.matrix = matrix;
+ this.colorTransform = colorTransform;
this.childMovieClips = {}; // name => movieClip
this.clearControlTags();
//
this.canvas = canvas;
this.canvasDirty = false; // dirtyFlag
//
- this.displayList = {}; // depth => [tag, matrix, colorTransform]
+ this.displayList = new FlappDisplay();
//
this.totalframes = 0;
this.currentFrame = 0;
+ this.playing = true;
+ // this.loop = true;
+ this.loop = false;
+ var actionVarriableTable = {};
+ var actionVarriablOrigKeys = {};
};
FlappMovieClip.prototype = {
clearControlTags: function(controlTag) {
this.controlTagsList = [[]]; //
+ this.actionTagsList = [[]];
this.labelMap = {}; // label => frameNum
this.framesLoaded = 0;
},
appendControlTag: function(controlTag) {
// console.debug("FlappMovieClip::appendControlTag");
+ if (controlTag.code === 12) { // DoAction
+ this.actionTagsList[this.framesLoaded].push(controlTag);
+ return ;
+ }
this.controlTagsList[this.framesLoaded].push(controlTag);
if (controlTag.code === 1) { // ShowFrame
this.controlTagsList.push([]);
+ this.actionTagsList.push([]);
this.framesLoaded++;
} else if (controlTag.code === 43) { // FrameLabel
this.labelMap[controlTag.name] = this.framesLoaded;
}
},
control: function(dict) {
- console.debug("FlappMovieClip::control");
- var tag, i, l;
if (this.framesLoaderd < this.totalframes) { // imcomplete
if (this.currentFrame < this.framesLoaderd) {
return false; // idle
}
}
+ for (var mc in this.childMovieClips) {
+ this.childMovieClips[mc].control(dict);
+ }
+ if (this.playing) {
+ this.controlThis(dict);
+ }
+ return true;
+ },
+ controlThis: function(dict) {
+ console.debug("FlappMovieClip::controlThis");
+ var tag, i, l;
+ var defineTag;
+ if ((this.currentFrame < 0 ) || (this.totalframes <= this.currentFrame)) {
+ this.currentFrame = 0;
+ }
var controlTags = this.controlTagsList[this.currentFrame];
- this.actionTagList = [];
+
for (i = 0, l = controlTags.length ; i < l ; i++) {
- tag = this.controlTags[i];
+ tag = controlTags[i];
switch (tag.code) {
case 1: // ShowFrame
break;
- case 12: // DoAction
- this.actionTagList.push(tag);
- break;
case 26: // PlaceObject2
// set display List;
+ if (tag.id === null) {
+ defineTag = null;
+ } else {
+ defineTag = dict.get(tag.id);
+ }
+ this.displayList.set(tag.depth, defineTag, tag);
break;
}
}
- this.currentFrame = 0;
- return true;
},
action: function() {
- console.debug("FlappMovieClip::action");
- var tag, i, l;
- for (i = 0, l = this.actionTagList.length ; i < l ; i++) {
- tag = this.actionTagList[i];
- ;
+ for (var mc in this.childMovieClips) {
+ this.childMovieClips[mc].action();
+ }
+ if (this.playing) {
+ this.actionThis();
}
+
},
- render: function(canvas, matrix, colorTransform) {
- console.debug("FlappMovieClip::render");
+ actionThis: function() {
+ console.debug("FlappMovieClip::actionThis");
+ var actionTags = this.actionTagsList[this.currentFrame];
+ for (var i = 0, l = actionTags.length ; i < l ; i++) {
+ var tag = actionTags[i];
+ var movieClip = this;
+ FlappAction.exec(tag, movieClip, this.rootMovieClip);
+ }
+ },
+ increment: function() {
+ for (var mc in this.childMovieClips) {
+ this.childMovieClips[mc].increment();
+ }
+ if (this.playing) {
+ this.incrementThis();
+ }
+ },
+ incrementThis: function() {
+ this.currentFrame++;
+ if (this.totalframes <= this.currentFrame) {
+ if (this.loop) {
+ this.currentFrame = 0; // play
+ } else {
+ this.playing = false;
+ }
+ }
+ if (this.totalframes === 1) {
+ this.playing = false;
+ }
+ },
+ render: function(canvas) {
+ for (var mc in this.childMovieClips) {
+ this.childMovieClips[mc].render(canvas);
+ }
+ if (this.playing) {
+ this.incrementThis();
+ }
+ },
+ renderThis: function(canvas) {
+ console.debug("FlappMovieClip::renderThis");
+ },
+ setVariable: function(key, value) {
+ var lcKey = key.toLowerCase();
+ actionVarriableTable[lcKey] = value;
+ actionVarriablOrigKeys[lcKey] = key;
+ },
+ getVariable: function(key) {
+ var lcKey = key.toLowerCase();
+ if (lcKey in actionVarriableTable) {
+ return actionVarriableTable[lcKey];
+ }
+ return null;
+ },
+ gotoFrame: function(frameNum) {
+ this.currentFrame = frameNum;
+ },
+ gotoLabel: function(frameLabel) {
+ frameNum = labelMap[frameLabel];
+ this.currentFrame = frameNum;
}
};
global.FlappMovieClip = FlappMovieClip;