Good day to everyone. I'm here today to seek help about Flash CS4 and ActionScript 3.0. The story starts when one day, my boss asked me to make a flash presentation about their upcoming user training for a newly developed software. I was enthusiastic and excited about it because it's been a long time that I did not use Flash (note that I don't have any experience in ActionScript 3.0). At first, everything was a bit rough as I need to recall how to properly use the frames to create a successful animation. As I was about to finish the project, my boss approached me again and asked if I could insert a menu page in front so that the users won't have to replay the whole thing again just to look for a little something on that part of the movie. So yea, at first I was abit hesitant to accept. I said that it will work with Powerpoint. But she's a total pusher and I was forced to say yes. Now I'm having this problem about how to make a flash button load a swf movie. I've tried searching all over the net for tutorials but most of the times the "getUrl" and other stuff are said to be outdated. Help please?
This answer is based on my interpretation of your question, which is: "Can I create an SWF that acts as a menu, and load in different SWF files based on what the user clicks in the menu?".
The answer is of course yes, and here's how:
A few things you need to understand / look at:
Here's a function to load your SWF:
var loadedSWF:Loader = null;
/**
* Loads an SWF and adds it to container once complete
* @param file The URL to the SWF to load
* @param container The container to add the SWF to
*/
function loadSWF(file:String, container:MovieClip=null):void
{
if(container == null) container = MovieClip(root);
// removes the previously loaded SWF
if(loadedSWF != null)
{
if(loadedSWF.parent) loadedSWF.parent.removeChild(loadedSWF);
}
var req:URLRequest = new URLRequest(file);
loadedSWF = new Loader();
loadedSWF.load(req);
addChild(loadedSWF);
}
And here's how to use this function when you click a button:
mybutton.addEventListener(MouseEvent.CLICK, _click);
function _click(e:MouseEvent):void
{
loadSWF("myfile1.swf");
}
As per question in comments:
You could use navigateToURL()
instead of a Loader and set up your external SWFs on different pages (like a website basically). If you're going to do this it might even make more sense to keep your main index page just plain HTML and launch your pages in new windows. If you still want to have your main page as flash then clicking through to a page in a new window is done like this:
button.addEventListener(MouseEvent.CLICK, _click);
function _click(e:MouseEvent):void
{
var req:URLRequest = new URLRequest("somepage.html");
navigateToURL(req, "_blank");
}