0
votes

I have a scene that contains a movie clip. That movie clip has a button that controls the y position of a symbol in the scene. What I tried to do is move on to the next scene when the symbol reaches certain y values. I used gotoAndPlay when the desired y position was reached, the new scene was switched to but an error appeared on output as indicated by the title. This is the code that appears in the movie clip:

launch_btn.addEventListener(MouseEvent.CLICK, init_launch)

function init_launch(evt:MouseEvent):void
{
    MovieClip(root).launch_video.play();
    var k = setTimeout(launch, 1);
}

function launch():void
{
    trace(MovieClip(root).rkt.y);

    if(MovieClip(root).rkt.y != null)
    {
        //progressively changing the y position
        if(MovieClip(root).rkt.y != null)
        {
            if(MovieClip(root).rkt.y < 600)
            {
                MovieClip(root).rkt.y -=0.3
            }
            if(MovieClip(root).rkt.y < 500)
            {
                 ...
            }
            setTimeout(launch, 1);

            if(MovieClip(root).rkt.y < -150)
            {
                MovieClip(root).gotoAndPlay(1, "Scene 3")
            }
    }
}

Currently, as compile this code the error points to the line "trace(MovieClip(root).rkt.y);".

What I don't get is why rkt suddenly becomes null when I try to go to a different scene. I tried checking if the property is null but that doesn't help.

I tried removing eventListener, and calling functions that resided in the actions layer of the scene itself (the original one) instead of directly going to the scene from the movie clip.

All in vain.

Any ideas?

2

2 Answers

1
votes

What I don't get is why rkt suddenly becomes null when I try to go to a different scene. I tried checking if the property is null but that doesn't help.

It's the object that's null, not the property.

I tried removing eventListener

Which won't help much given that the continuing calls to launch are not triggered by an event but setTimeout which will keep firing.

Stop using setTimeout and use a Timer. This allows you to remove the event listeners properly and actually stop it.

-1
votes

MovieClip(root) was actually the property that turned null when the y position was reached. I modified the condition inside launch() to handle that:

 function launch():void
 {
    if(MovieClip(root)!= null)
    {
        rest of code...
    }
 }

I really hope this would help others. I only posted a question here after much research online and particularly here. It appears this error plagues a lot of developers.