View Full Version : Null Object Reference in new Frames
mad_man
July 5th, 2008, 08:38 PM
Hello,
I keep on having trouble accessing MovieClips in new frames through actionscript. Lets say for example I have movieclip mc on frame 2 of my fla. Then in actionscript if i do gotoAndStop(2) and then try to access mc I get an Null object reference error. And i understand that it is because the mc has not been created yet even though i told it to go to frame 2. Is there a way to know when the object has been initialized so that I can use it. Or is there a workaround for this problem other than creating the mc in as3 or changing the visibility of the mc?
Thanks.
TheGoods
July 6th, 2008, 11:57 AM
I think this should work
///////////////////////////////////////
mc.addEventListener(Event.Load,yourfunction);
function yourfunction(){
mc.gotoAndPlay(2);
}
mad_man
July 6th, 2008, 11:02 PM
well if my mc is on the second frame, its not going to be instantiated in the previous frames for me to add an event listener
sekasi
July 6th, 2008, 11:46 PM
Look into addframescript.
.ral:cr
July 7th, 2008, 12:58 AM
i think that your thinking is bad, do not use frames at all :)
Anogar
July 7th, 2008, 01:22 AM
i think that your thinking is bad, do not use frames at all :)
There are certain animations that are most certainly best done with frames - complex hand-done animations, or another example is embedded FLVs.
senocular
July 7th, 2008, 10:33 AM
There are a number of issues with Flash Player 9 and child access after frame navigation (which I made sure were completely if not mostly resolved for FP10 ;)). Right now, I think the most reliable method, if not using a frame script, is to use the movie clip's constructor to call a callback or some pre-defined method in its parent (your target timeline) or use the timeline's Event.ADDED event to detect when it's been added to the display list. One thing about ADDED is that it will fire for all child movie clips, so you might want to check event.target to make sure you're getting what you expect, and maybe use a switch statement if you're performing a number of different actions for different movie clips.
mad_man
July 7th, 2008, 11:30 PM
wow thank you for the help. ive had this problem a while and had to do some shady workarounds.
how did yall find out about addFrameScript if its not documented?
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.