[CS3] AS3 Rending issue which is annoying me greatly
As much as I like AS3, there are a lot of little things which make Willoughby go mad (and refer to himself in the third person).
In AS2, I had a custom class that controlled the playhead, allowing me to play movie clips forward, backwards, skip frames, play to a certain frame, or whatever.
I recreated this code in AS3, but if there are any movie clips animating inside of the movie being manipulated, they do not animate at all.
I have created a little demonstration to show you what I mean. All the code does is move the playhead forward, and when it reaches the final frame, moves the playhead backwards.
I changed it to a graphic on a loop and it worked fine. But i'm guessing that would cause issues somewhere else along the line.
"I'd only told them the truth. Was that so selfish? Our integrity sells for so little, but it is all we really have. It is the very last inch of us, but within that inch, we are free."
yeah, it seems that whenever a MovieClip enters a new frame (by means of code) it is reset. If you don't control the timeline through code, the child MovieClip's play properly, also, moving the object on its x axis work's as well.
here's a simple function I created to deal with it:
Code:
var dir:Number = 1;
function onEnterFrame(evt:Event) {
this.gotoAndStop2(currentFrame + dir);
if (currentFrame == totalFrames){
dir = -1;
}
else if (currentFrame == 1){
dir = 1;
}
}
MovieClip.prototype.gotoAndStop2 = function(frame:Object, scene:String = null):void {
this.gotoAndStop(frame, scene);
for(var i:int = 0; i < this.numChildren; i++){
var child:MovieClip = this.getChildAt(i) as MovieClip;
if(child != null){
var frame:int = child.currentFrame >= child.totalFrames ? 1 : child.currentFrame + 1;
child.gotoAndStop2(frame);
}
}
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
of course you could use the Event.RENDER event on all your children and then on that eventHandler advance the child's frame. The MovieClip has changed quite significantly in AS3, I would try to avoid it or change the way you create your animations.
I realise this is an example, but her movement could easily be replciated using an x coordinate.
Code:
stop()
var dir:Number = 1;
var index:int = 1;
function onEnterFrame(evt:Event) {
index += dir;
chunners.x = (index / totalFrames) * stage.stageWidth
//this.gotoAndStop2(currentFrame + dir);
if (index == totalFrames){
dir = -1;
}
else if (index == 1){
dir = 1;
}
}
Although I realize this is an example her movement could easily be replicated using an x coordinate, most of the time when I use this code, there is some complex animation created by our graphic designer.
Admittedly, there is always the animation/XML thing, but I'm not sure I want to deal with that every time I need to manipulate a complex animation.