R – Multi-pages Flash application

actionscript-3flash

I am very new to Flash and I need help to get started with building multi-pages Flash application.

I managed to open another swf file (called Page1) from within the main swf by calling this function

    private function LoadExternalSwf(): void
    {
        var loader:Loader = new Loader();
        var urlReq:URLRequest = new URLRequest("page1.swf");
        loader.load(urlReq);
        addChild(loader);
    }
  1. How do you add a sort of "Back" button to Page1 so that it will close itself (so that we are back to the main screen)?

  2. If Page1 were a movie, is it possible to automatically close it after it finishes playing?

(I am using Flash CS3, Flex Builder 3, AS3)

Thank you

Best Answer

How do you add a sort of "Back" button to Page1 so that it will close itself (so that we are back to the main screen)?

There are many ways of doing this. You could just hide the page by setting it's visibility to false, you could just move it off stage so that it can't be seen or you could remove the movieclip altogether (along with probably other options). Basically it's completely up to you and you must choose the best option to suit your purposes.

In your example you want page1.swf to have a button that, when clicked on, tells it's parent to do something. I would personally recommend that this happens by dispatching an event when the button is clicked. The parent can then listen to page1 for that event. When it catches that event, you can then choose what to do with page1.

I suggest you have a read of some articles regarding events in actionscript 3 to find out how this is achieved. Try this one for starters

If Page1 were a movie, is it possible to automatically close it after it finishes playing?

Yes this is also possible and again i would use the same method as stated above. Dispatch an event on the final frame (or when at least you know the final frame has been hit) that tells it's parent to do something.

Related Topic