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?
-
What do you mean have a 'flash button' open a url movie? Do you mean have a button in a flash movie go to different parts of the same movie (e.g. goToAndPlay()) or have a flash movie in a browser go to a different page or something else? – WirthLuce May 17 '11 at 01:22
-
I mean, I'm now having problem with the Menu Page. I prefer it to be a seperate document than the content (which is the training presentation). Inside the menu page should be buttons that when clicked, they should be able to load/open the swf file to a new window so that the menu page won't be overlapped and the user can go to it anytime to open other contents in the menu page. – Question Man May 17 '11 at 01:37
-
I would suggest purchasing a flash template and altering it for your needs. There is a learning curve for AS3. If you go to a site like http://activeden.net/category/flash/menus-buttons you can purchase one very cheap there and get author decent support. – The_asMan May 17 '11 at 01:38
-
Alternatively I can create one for you.. Assuming your expectations are minimal. – Marty May 17 '11 at 01:41
1 Answers
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:
- Loader and URLRequest classes.
- Event Listeners for buttons.
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");
}

- 39,033
- 19
- 93
- 162
-
Thanks a lot. I will try that. Sorry I don't have an account to score the answer. – Question Man May 17 '11 at 01:43
-
Hey. I have one last problem. It says 1120: Access of undefined property button. How do I fix that? The problem is found in this lines button.addEventListener(MouseEvent.CLICK, _click); function _click(e:MouseEvent):void { loadSWF("Main.swf"); } – Question Man May 17 '11 at 01:50
-
You need to create the button and in the properties panel give it the instance name "mybutton". From here you can create multiple buttons that load different SWFs and give them different instance names. Then just copy & paste the code for the click event and replace "mybutton" with whatever you name the button and replace the file name with whatever file you want to load. – Marty May 17 '11 at 01:52
-
-
OMG. Now I'm having this Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found. I tried the full directory address of the file but it's still not working. – Question Man May 17 '11 at 02:11
-
Full directory address won't work. You'll either have to specify a remote URL (like http://domain.com/file.swf) or a path from the SWF (like files/thing.swf if there were a files folder in the same directory as the SWF) – Marty May 17 '11 at 02:43
-
Hey. It worked by changing a backward slash to a forward. Now, is there anyway to open the new swf in another window? – Question Man May 17 '11 at 03:17
-
-
Im not really good at english so Ima use an example. Like for a web browser(e.g. Firefox). Instead of opening a link on the same window. I would like to open the link into a new window. Same to flash, I want the file to open in another window and not to overlap the current swf. Is that possible? – Question Man May 17 '11 at 03:24
-
Um yep but if you want to do that then you could have saved yourself the trouble of using a loader and just use normal links in your flash to navigate to other pages with flash embedded on them. I'll update my answer. – Marty May 17 '11 at 03:32
-
Ok then. Thanks a lot man. You're really kind. I wouldn't have progressed without you. It's really nice to know that people like you still exists in this world. :D – Question Man May 17 '11 at 03:34