Reputation: 5
I have a flash file where the first frame contains two buttons, one of which takes the user to the second frame, and the other takes them to the third frame. At each of those frames, various text fields and variables can be manipulated via SimpleButtons. Both Frame 2 and Frame 3 have "back" buttons to take them back to Frame 1.
Currently when the user navigates back to Frame 1 for the second time (thus playing it for a third time), my second button appears to no longer exist, and I receive an error. Both buttons on Frame 1 were placed via the Flash IDE. Why is my button popping out of existence, when it did perfectly fine the previous two times? Below is my code for Frame 1. The "back" buttons simple remove event listeners and then call gotoAndStop(1)
var inited:Boolean;
var cache:SharedObject;
var libsans:Font = new libsansreg();
this.addEventListener(Event.ENTER_FRAME, frameEnter);
stats.addEventListener(MouseEvent.CLICK, statsclicked);
modules.addEventListener(MouseEvent.CLICK, modsclicked);
function initcache():void
{
this.cache = SharedObject.getLocal("RPG_Shooter")
}
function frameEnter(e:Event):void
{
if (!inited)
{
inited = true
initcache()
this.gotoAndStop(1)
}
}
function statsclicked(e:MouseEvent):void
{
this.removeEventListener(Event.ENTER_FRAME, frameEnter)
stats.removeEventListener(MouseEvent.CLICK, statsclicked)
modules.removeEventListener(MouseEvent.CLICK, modsclicked)
this.gotoAndStop(2)
}
function modsclicked(e:MouseEvent):void
{
this.removeEventListener(Event.ENTER_FRAME, frameEnter)
stats.removeEventListener(MouseEvent.CLICK, statsclicked)
modules.removeEventListener(MouseEvent.CLICK, modsclicked)
this.gotoAndStop(3)
}
Upvotes: 0
Views: 52
Reputation: 82028
I actually had similar problem at one point. It has to do with garbage collection which is not the best in Flash to begin with, but the IDE's compiler settings make it so much more insane. There are a couple of tricks you can try which might help.
foo = null
on frame one)var foo:MovieClip
on frame 1. repeat for all MovieClips which you might be using that are named ahead of time.Upvotes: 1