Copy link to clipboard
Copied
Hello.
I have used the loader script to load an external swf into current project. I have added a button to unload the external file when wanted, and was wondering if you could have multiple functions for that button, so that when you click it to unload it works as a 'home' button as well, and takes the user back to the mainpage again?
AS3 btw.
Might be wise to mention that im kinda new to adobe flash and as3, and not sure if the way i have used to load the external swf was the easiest. Seems like a few have had some issues with this subject before me as well.
All pointers in the right direction is appreciated. Cheers.
1 Correct answer
You can reduce yourt button code to...
btnHeim.addEventListener(MouseEvent.CLICK,heimClick);
function heimClick(e:MouseEvent):void {
loader.unload();
gotoAndStop(1,"Mainpage");
}
As far as the error goes, go into your Flash Publish Settings and select the option to Permit Debugging. Then your error message should include a reference to the line number of the code that is triggering the problem. It will appear just after where it say frame2. So whatever line in frame 2 that is identified is
...Copy link to clipboard
Copied
If you plan to have your button do multiple things, you can normally have all those things executed in one function. So whatever function your event listener calls can have the code to unload the external file as well as have it execute whatever code is needed to behave as a home button. You can have separate functions that the event handler function calls as well. If the intention is to do different things at different times with the same button, then you would need some conditional code or to assign different listeners at different times that call different functions.
Copy link to clipboard
Copied
Thanks alot for answer Ned Murphy.
As I've might failed to mention, is that the button is intended to do two things, unload and return to main page, at the same time. So basically a one click operation.
To update the situation, I've tried this as a code;
btnHeim.addEventListener(MouseEvent.CLICK,unloadSwf);
function unloadSwf(e:MouseEvent):void {
loader.unload();
}
btnHeim.addEventListener(MouseEvent.CLICK,tilbaks);
function tilbaks(event:MouseEvent):void{
gotoAndStop(1,"Mainpage");
}
It kind of work, as it unloads and takes you back to the main page. Only thing then is that the buttons on mainpage doesnt work any longer, and one of them disappear?
I've never been this deep into AC3 i think, so not sure what the problem is, except for the fact that there is some issues going on.
This is the error that shows up on 'output' after btnHeim is clicked.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Mappevurdering_web_fla::MainTimeline/frame2()
at flash.display::MovieClip/gotoAndStop()
at Mappevurdering_web_fla::MainTimeline/tilbaks()
Thanks again
Copy link to clipboard
Copied
You can reduce yourt button code to...
btnHeim.addEventListener(MouseEvent.CLICK,heimClick);
function heimClick(e:MouseEvent):void {
loader.unload();
gotoAndStop(1,"Mainpage");
}
As far as the error goes, go into your Flash Publish Settings and select the option to Permit Debugging. Then your error message should include a reference to the line number of the code that is triggering the problem. It will appear just after where it say frame2. So whatever line in frame 2 that is identified is where the problem exists. As far as the 1009 error goes, there are a variety of reasons for it occuring..., but they all point to the same basic problem... whatever object the code is talking to does not exist where the code is executing...
This could mean that the object....
- is not in the display list
- doesn't have an instance name (or the instance name is mispelled)
- does not exist in the frame where that code is trying to talk to it
- is animated into place but is not assigned instance names in every keyframe for it
- is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).
Copy link to clipboard
Copied
See that is so much better! Thanks alot! Looks way better as well as there isnt loads of noob scripts filling up my page
The button does now work perfectly as intended,so thats very very good.
I did as you mentioned, and selected Permit Debugging, but it seems like it only removed the error messages, and kept the error. In order to make it work properly after unload and return to page, I have to go all the way out to the start page to 'reset' the page. Dont know if this have any effect on the subject, but its all done in frame1 in the 'Timeline', and it consists of 4 scenes, all linked together in one way or another.
I think its clearly that Im much more unexperienced at flash than I thought I was at the start of the project, and that it goes way deeper than I thought as well. Powerful tool.
Anyways, Im putting your last post as the right answer, as it is the right answer to the actual question, so thanks alot for helping out with that bit
Copy link to clipboard
Copied
You're welcome. I recommend you avoid using scenes and just use the one scene's main timeline. Either control visibility of the content you have in different scenes and/or spread it out along the tmeline. When you use scenes the program ends up doing that anyways, combines all the scenes into one timeline. I say this mainly because I have always found scenes to be problematic and never used them in my own work... I just encountered them in working with other people's files.
Copy link to clipboard
Copied
Ned Murphy wrote:
You're welcome. I recommend you avoid using scenes and just use the one scene's main timeline. Either control visibility of the content you have in different scenes and/or spread it out along the tmeline. When you use scenes the program ends up doing that anyways, combines all the scenes into one timeline. I say this mainly because I have always found scenes to be problematic and never used them in my own work... I just encountered them in working with other people's files.
Oh, thats a bit of a blow..hah..
The only way I've learnt this so far, is by using scenes, so not sure how timeline works properly. Only time I've tried a timeline function was for a small photogallery, which was put on scene2 out of a main scene and photogallery scene in one file.
So you suggest working with the timeline rather than scenes, for my next project that I start next week?
Its going to be a bigger photogallery page with;
-intro page
-main page
-about 4 underpages with aprox 10+ pics in each as thumbnails and slideshow
Better get back to sort out the error with missing buttons..
Thanks again mate.
Copy link to clipboard
Copied
There are two approaches I usually follow with timeline designs, often mixing the two, though these days I tend to keep things in the first frame more often than anything. You can create sections as movieclips and keep them all in the same frame and just control visibility, or you can create your content on different sections of the timeline and navigate to them. The first approach works welll when you have a scenario where you want to retain the conditions that you established in another section... say in one section you have a gallery and clicking on an image leads to a section that explains details of what you clicked. If you want to return to the gallery where you left it, using the visibility approach makes it as easy as making it visible again.
Copy link to clipboard
Copied
Thanks alot for the help!
This is something I definitly need to look into next week, before I start the actual work. I'll probably be around with more noobish question the next few months
This is what happens when they put a 3D designer into scripting!
Thanks alot again.

