Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6987665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:58:01+00:00 2026-05-27T18:58:01+00:00

This might be a simple question, but am trying to access a button inside

  • 0

This might be a simple question, but am trying to access a button inside an external swf file that I loaded. Problem is every time I try to access this button I get an error saying that it’s null!

Any ideas why this is happening? I tried searching for similar posts and I did find some, but this problem still persists

Here is my code:

public class DocumentClass extends Sprite
{
    public var loader:Loader;
    public var swfFile:URLRequest;
    public var container:MovieClip;

    public function DocumentClass() 
    {
        super();

        // support autoOrients
        stage.align = StageAlign.TOP_LEFT;
        stage.scaleMode = StageScaleMode.NO_SCALE;

        loader = new Loader();
        swfFile = new URLRequest("swfs/TestScreen.swf");

        loader.load(swfFile);
        addChild(loader);

        button.addEventListener( MouseEvent.CLICK, onClickReturnMainMenu ); // PROBLEM HERE




    }

    private function onClickReturnMainMenu( event:MouseEvent ):void
    {
        trace("TEST-TEST");
    }

Thanks =D

EDIT: here is the edited code

public class DocumentClass extends Sprite
{
    public var loader:Loader;
    public var swfFile:URLRequest;
    public var container:MovieClip;

    public function DocumentClass() 
    {
        super();

        // support autoOrients
        stage.align = StageAlign.TOP_LEFT;
        stage.scaleMode = StageScaleMode.NO_SCALE;

        loader = new Loader();
        swfFile = new URLRequest("swfs/TestScreen.swf");

        loader.load(swfFile);

        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);




    }

    private function onClickReturnMainMenu( event:MouseEvent ):void
    {
        trace("ASDSADSADSAD");
        //dispatchEvent( new ButtonEvent( ButtonEvent.MAINMENU ) );
    }


    private function onLoadComplete(evt:Event):void
    {
        addChild(loader);

        var button:SimpleButton = loader.content.button
        button.addEventListener(MouseEvent.CLICK, onClickReturnMainMenu);   


    }

Now this should work, code-wise I think its correct. The problem is that loader cant find the required button. There is indeed a button in the loaded movieClip with an instance name of “button”, I double checked that…Any suggestion guys?

EDIT2 finally got it working thanks to this http://www.kirupa.com/forum/showthread.php?301313-Accessing-MC-instances-inside-loaded-SWF basically i was just a layer too high and this is why i couldn’t access anything…SO STUPID OF ME…well atleast its over now. Thanks for the help guys =D

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:58:01+00:00Added an answer on May 27, 2026 at 6:58 pm

    You’ve got 2 problems here…

    1. You’re not waiting for the swf to load before you attempt to access the button.
    2. Your method for accessing the button is incorrect.

    You first need to add an Event.COMPLETE listener to loader.contentLoaderInfo:

    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
    

    Then you need to make an event handler:

    protected function onLoadComplete(evt:Event):void
    {
        var button:SimpleButton = loader.content.button;
        button.addEventListener(MouseEvent.CLICK, onClickReturnMainMenu);
    }
    

    That should do it for you, assuming your button is in the root of the loaded movie with an instance name of “button”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry that the question of this problem might be a bit vague. I'm trying
This might be a simple question. But I am trying to use a rule
This might seem a simple question but I've been trying for a couple of
This might be a simple question but I'm just picking this up so please
This might be a simple question, but i can't seem to grasp it. I
There might be a really simple solution to this question, but i just don't
Now this might sound simple, but I'm a bit mixed up. I am trying
This might be a pretty straightforward question, but I'm trying to understand some of
This might be simple but I am new to Oracle. I am using Oracle
This might be a simple answer, but I am having some issues writing this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.