Disable button from loaded movie clip?

adrian7474
adrian7474 used Ask the Experts™
on
Is there anyway to have an externally loaded swf disable a button on the swf that loaded it.
Let me explain my situation to clarify.

I have a main fla file that has navigation buttons (next and previous page). Once they are clicked, they go to a certain frame, and then load an external swf. I do this to keep the main fla light weight. Problem is, the content overlays the next and previous buttons from the main fla and those button still work. I would like to disable them once the external swf is loaded and once it is closed, reactivate them. I tried putting root.exampleinstancename.visible = false, but they following error occurs
 "1119: Access of possibly undefined property main_mc through a reference with static type flash.display:DisplayObject.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
The cleanest option would be to have an event handler inside your main swf so that once the external swf is loaded it disables the buttons within itself.

Otherwise you are going to have to do quite a bit of fudging to get it to work.
Top Expert 2009

Commented:
i agree setup a function do toggle your buttons and call that instead.
so as you load the external swf, disable the button.

Author

Commented:
Hey Guys, much thanks. I am a little new a this though. I understand what your saying, just not sure how to implement. I am loading the external swf with this code:
var FlashLoader:Loader;
FlashLoader = new Loader();

mapsloader.addChild(FlashLoader);

FlashLoader.load(new URLRequest("Map.swf"));

--This swf has a map that is clickable, but overlays existing buttons on the main movie. So how would i disable the bottom layer button with handler?
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
ok so with your loader, do something like this.

Keep in mind this is all in your main swf.
var FlashLoader:Loader = new Loader();
FlashLoader.addEventHandler(Event.COMPLETE, loadingComplete);
 
mapsloader.addChild(FlashLoader);
 
FlashLoader.load(new URLRequest("Map.swf"));
 
THEN OUTSIDE THE FUNCTION WHERE YOU HAD THE ABOVE CODE
 
function loadingComplete(e:Event):void
{
  PUT THE CODE IN HERE TO REMOVE/HIDE THE BUTTONS
}

Open in new window

Author

Commented:
Hey, sorry Tried getting it to work,am still having trouble. I partially got it to work.

I have attached code so far.

Thing is the swf that is loaded, has a close button on it, that i would like to unload the movie and once unloaded, the button again becomes visible or active. Is this possible? I have tried putting this, root, parent before the instance name, but i dont think it sees buttons on the swf that is loaded.
Help me obi-one kenobi...
stop();
 
//-----------------
var FlashLoader:Loader = new Loader();
FlashLoader.addEventListener(Event.COMPLETE, loadingComplete);
 
 
btn1.buttonMode=true;
btn2.buttonMode=true;
btn3.buttonMode=true;
 
btn1.addEventListener(MouseEvent.CLICK,loadingComplete);
 
function loadingComplete(e:Event):void
{
		loader1.addChild(FlashLoader);
 
		FlashLoader.load(new URLRequest("test1.swf"));
		btn1.visible = false;
 
		}
		
btn2.addEventListener(MouseEvent.CLICK,unloadswf1);
 
function unloadswf1(event) 
{
		FlashLoader.unload();
		btn1.visible = true;
		}

Open in new window

Commented:
Usually if you do

parent.removeChild(this);

It will remove itself.

Author

Commented:
it removes it when i test the movie(swf) within that fla, however when the main swf loads it, this error occurs:
Error: Error #2069: The Loader class does not implement this method.
      at Error$/throwError()
      at flash.display::Loader/removeChild()
      at test1_fla::MainTimeline/closeSwf()
Top Expert 2009

Commented:
adrian, why are you loading the swf into a Loader then adding the Loader to another Loader?

Author

Commented:
Not sure, I am trying to keep the file size of my main fla file down, so I  am loading external swfs that contain different content. For example my main movie moves up and down the time line and once on that frame, loads an swf with its own content. The problem is the content that gets loaded sometimes overlays the buttons from the main movie. I used the load complete function to disable to buttons undernieth, however, i have a button on the movie the was loaded that says 'close' and would like it to close or unload that movie when they click it and reactive the button on the main time line that as disabled.  
However, I can't for the life of me figure out how to tell the movie that was loaded to unload it self. I am probably making this more complicated than it has to be, but seems like a fairly common thing to do no? Any help would be greatly appreciated.
cheers
a
Top Expert 2009

Commented:
well lets see if danyul comes up with something otherwise i'll need to see what you're doing if you can zip it up and upload.

Author

Commented:
i wish i could attach the fla, but this site doesn't allow .fla files. Weird, considering its a computer tech based site. I even put them into zip and it recognized that there were .fla files inside.

Commented:
Hey, sorry I was trying to stay off my computer as much as possible this w/e. I hate these frigging things.

I do have a solution however it will probably require some reworking of your code and the direction you are trying to take.

I just need one thing clarified first of all just to make sure I'm pointing you in the right direction.

You current structure from what I gather is Parent (main fla) -> Child (page fla) -> Grandchild (page content). Please correct me if I am wrong.

The approach which actionscript and most OOP languages for that matter take is that of an actual (functional) family. he Parent can tell the child what to do and the child can tell the grandchild what to do.

So if you are wanting to remove the child (and by extension the grandchildren) you would have the content of your parent swf on the bottom layer, the child content on a second layer and then the close button on the 3rd layer. So the close button would actually be in the main fla but it's on a layer above the child fla.

You would insert the child fla to the layer under the buttons by doing an addChildAt function call but of course you are going to have to know what layer the button is on.

This way you can program the button to do a removeChild or removeChildAt on the child fla as needed. If will also handle the reinstating of the original buttons etc.

if you are trying to get rig of the grandchildren only then the same concept would apply except you would work inside the child fla.

I really hope I haven't made this too confusing. But if you remember the family structure then you should be able to sort it out.
Top Expert 2009

Commented:
i've had a word with the ppl about the file types but for now if you want you can change the .fla extension to .txt.
thanks all, i have abandoned this for now and found a work around. Thanks all for the help :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial