views:

129

answers:

3

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

+2  A: 

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.

James Hay
Thanks James. I've read that link and I'm gonna try it.Now is there any standard event type to dispatch to tell the parent that it has finished? (or any standard/common name or way of dispatching the event?)Thanks!
A: 

How do you dispatch an event from Page1, and how do you catch it on the main swf?

A: 

Solution:

From page1:

// Dispatch a "pageFinish" event to the loader/parent/container if any
if (loaderInfo.loader)
 loaderInfo.loader.dispatchEvent(new Event("pageFinish", true));

From the main swf:

// Listen for the "pageFinish" event
loader.addEventListener(EVENT_PAGEFINISH, OnPageFinish);

...

private function OnPageFinish(event: Event): void
{
 ...
}