Hi,
I got a little trouble when I was using Event.FRAME_CONSTRUCTED with MovieClips, I want to know if I was rgiht about: If a movie clip contains only one frame, when MovieClip.goto() function is called, Event.FRAME_CONSTRUCTED is dispatched depends on flash player version.
I realize it when I was debugging something else, so is that correct, and is there any way that I can know if a movieclip is already "FRAME_CONSTRUCTED" so I don't need to add event listener(such as, mc.isConstructed?).
Thank you for any information.
Hello, kglad!
OK, let me make myself clear first.
"What are you trying to do?", I am caching movieclips into sprite sheet, when I draw() certain frame of one movieclip onto a bitmapData, the movieclip need to get ready, so I draw it when this movieclips dispatches FRAME_CONSTRUCTED event, which means this frame is ready( i guess you know it ). So that's what I'm doing, then I found in different run-time, movieclips dispatch FRAME_CONSTRUCTED event differently( and I assum this happens more offen when there's more than one swfs are running, just because what I see, not very resonable). And it happen to those movieclips which have only one frame, so this is why I was ask for help.
So do you have any idea? Thank you advance!
Oh god, I am ashamed, I think I figure it out now.
First, when I say "I found in different run-time, movieclips dispatchFRAME_CONSTRUCTED event differently", this is because bug in my own code, event handler is fired, but before I trace() any information, it returns because some logic error. so I thought the event is not dispatched, I was wrong.
So now I need to do some demos to find out how movieclips dipatch FRAME_CONSTRUCTED(with those movieclips with one single frame, and in different version of flash players).
But I still what to know the answer to my second quesion " is there any way that I can know if a movieclip is already "FRAME_CONSTRUCTED" so I don't need to add event listener(such as, mc.isConstructed?)". It will be very helpful if there's any way.
And here I want to ask another quesion, it's a quesion related to the topic, but it's a different one. My quesion is : when I caching movieclips to bitmapData, I find somehow sometimes, the return of method MovieClip.getBounds() is not right EVEN I call it after or when the movieclip dispatches FRAME_CONSTRUCTED event. So what I got is a animation that is "trambling" because I got wrong position of some of the frames of that movieclip(I put bitmapData I cached onto Bitmaps, and set it's position according to what MovieClips.getBounds() tells me).
So any information or suggestion? Thank you.
if you want to apply the draw method to a movieclip frame, you should use the render event to ensure all objects in the frame have been rendered:
mc.addEventListener(Event.RENDER,renderedF);
drawF(1);
function drawF(frameNum:int):void{
if(mc.currentFrame!=frameNum){
stage.invalidate();
mc.gotoAndStop(frameNum);
} else {
renderedF(null);
}
function renderedF(e:Event):void{
// draw mc to a bitmap
frameNum++;
if(frameNum<=mc.totalFrames){
drawF(frameNum);
}
}
Thank you very very much, kglad,
I,m applying your method to my application,
I wonder if I have a lot of movieclip objects in my application which need to be cached, I think I need to call stage.invalidate() each time when I try to cache one of them, because I don't know/can't control the order in which those movieclip appears(most of displayobjects in my application is cached, so caching may happen when UI is loaded, animation is displayed. etc, yes I do it dynamicly).
1.So my quesion is, is there any affect to run-time performance if I call stage.invalidate() a lot?
2.If answer is true, when should I call stage.invalidate() so that all display object in the very frame can fire Event.RENDER( I read Event.RENDER api doc, I guess I only need to call it once, then all display object in the render list can dispatch Event.RENDER when it has next chance to render, am I right? and when is it not too late for me to call stage.invalidate() if I don't want to miss any display object?).
Thank you!
North America
Europe, Middle East and Africa
Asia Pacific