Hello to all! So, i’m loading a swf (image gallery) that fills the entire index movie’s stage. I created a “close” button in the swf. So, you’re inside the index movie and click gallery. It loads on top of the entire index movie so it appears as an image gallery with a solid background, none of the index elements are seen, but exist behind the gallery swf. What i want to do is access the close button in the gallery swf so when it’s clicked, it closes and the index stage is being viewed again. Ideas? Helpful Hints? Are the Lakers going win?
I’ve never created a public class. I’ve been learning AS3 on the fly. I’ve been reading over all kinds of tutorials and information on them today, but have had no luck creating one successfully. Is there a quick way to accomplish this for what you’ve provided me? Thanks!
This doesn’t seem to be working. I’ve added the code to my “index” page, and changed “buttonInstance” to “close_btn” which is what it’s named in the “gallery” swf. I’m not getting any errors when testing, the button just doesn’t work. Do i need to import “MovieClip” since it’s being used here? Also, i have a loader called “myLoader” that’s being used to load the swfs into “index”. Below is the code i’m using on each button to load the respective swf.
gallery_btn.addEventListener(MouseEvent.CLICK, galleryLoad);
function galleryLoad(Event: MouseEvent) {
myLoader.load(new URLRequest(“gallery.swf”));
stage.addChild(myLoader);
}
I didn’t have that line. So with that added, the code for my gallery button in the index swf that calls the gallery swf should be as so…
//Button code...
gallery_btn.addEventListener(MouseEvent.CLICK, galleryLoad);
function galleryLoad(Event: MouseEvent):void {
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
myLoader.load(new URLRequest("gallery.swf"));
stage.addChild(myLoader);
}
//The code you provided earlier...
var swf:MovieClip;
function onComplete(e:Event):void {
swf = e.target.content;
addChild(swf);
var button:MovieClip = swf.close_btn;
button.addEventListener(MouseEvent.CLICK, closeSWF);
}
function closeSWF(e:Event):void {
removeChild(swf);
}
I’m getting error #1119 “Possibly undefined property COMPLETE through a reference with a static type flash.events:MouseEvent”
Thanks again for all your help. This is the only issue i’m having with the entire site!
Thanks, i didn’t know that! So everything runs smooth until i click on the “gallery” button and i get an error message in my output window stating,
Error #1009: Cannot access a property or method of a null object reference.
at index_fla::MainTimeline/onComplete()
The button code hasn’t been changed, it’s still as follows:
gallery_btn.addEventListener(MouseEvent.CLICK, galleryLoad);
function galleryLoad(event: MouseEvent):void {
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
myLoader.load(new URLRequest("gallery.swf"));
stage.addChild(myLoader);
}
I know this error means that something is trying to load that isn’t there, but i’m confused as to how the “onComplete” line is causing this.
edit: Nevermind, i reread what you’d said and it made what i said pointless. haha
Ok, “close_btn” is the instance name (per the properties panel). I added the trace lines and get this…
loaded movie is [object MainTimeline]
button instance in loaded movie is undefined
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at index_fla::MainTimeline/onComplete()
When i comment out these three lines from the code, i just get the traces and no error.
addChild(swf);
var button:MovieClip = swf.close_btn;
button.addEventListener(MouseEvent.CLICK, closeSWF);
After reading the trace comment, i realized what could possibly be happening. Basically, i’ve got the index page with the “gallery” button. When pushed, it loads “models.swf” which displays thumbnails that are links to load individual galleries on top. The close button is in the gallery.swf, not the models.swf. I created a close button on the models.swf and got this trace & error:
loaded movie is [object MainTimeline]
button instance in loaded movie is [object SimpleButton]
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::SimpleButton@1d2dccc1 to flash.display.MovieClip.
at index_fla::MainTimeline/onComplete()
So, i changed this line, var button:MovieClip = swf.close_btn; to var button:SimpleButton = swf.close_btn; and it unloaded the “models.swf”!! But I want the “close_btn” in the “gallery.swf” that loads when a thumbnail is selected from “models.swf”. So, i removed the button, and when i select the models button, i get this trace & error:
loaded movie is [object MainTimeline]
button instance in loaded movie is undefined
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at index_fla::MainTimeline/onComplete()
So, since it worked for the “models.swf”(thumbnails), i know we’re close! I’ve uploaded what i’ve got so far so that you can get an idea of what i’m trying to achieve.
Click on “models” and then the first thumbnail. You can see how i load the gallery on top of the entire page and the close button in the top right.
You know, i tried that yesterday and kept getting errors. After reading your reply a couple times, implementing it, and trying to break down the errors, i figured it out! I’m using a grid component to load another grid component. I kept getting…
Error 1119: Access of possibly undefined property contentLoaderInfo through a reference with static type fl.containers:UILoader.
After reading that error several times, it clicked…remove “contentLoaderInfo”. Once i did, it works fine!! Thanks so much for all your help and guidance with this issue. You’ve been a huge help! As i learn AS3, i’m seeing how much more sense it makes than AS2 and others. Do you have any books, sites you recommend for AS3? Thanks again!!
hi i really need your help as i noticed you had the same issues as me and solved them. Here is my page link:
i really need to get this sorted thanks!