A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: [RESOLVED] Why does this basic button code not work?

  1. #1
    Member
    Join Date
    May 2000
    Posts
    80

    resolved [RESOLVED] Why does this basic button code not work?

    I have a very simple .fla

    one frame, one button on the main stage. I have named the button and when I right click>actions, it says I can't put actions in this area..

    so then I put the Actions on the main timeline/keyframe.

    the code below works, but I can't get code to work in the button that I placed on the main stage. This button is dynamically placed by the first two lines of code.
    Code:
    var MyButton:ButtonOne = new ButtonOne();
    MyButton.x = 100;
    MyButton.y = 300;
    addChild(MyButton);
    
    MyButton.addEventListener(MouseEvent.MOUSE_DOWN,startMC);
    
    function startMC(event:MouseEvent)
    {
    	myMovieClip.gotoAndPlay(11);
    }
    If I try to just have the code that looks something like this..

    Code:
    ButtonOne.addEventListener(MouseEvent.MOUSE_DOWN, startMC);
    //movie clip function startMC sits here..
    I get an error saying the symbol doesn't exist..
    WTF?
    pnj

  2. #2
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    In the properties of the button in the library did you set it to "export for actionscript" and give it the name "ButtonOne"?

  3. #3
    Member
    Join Date
    May 2000
    Posts
    80
    Yes, I did.
    pnj

  4. #4

  5. #5
    Member
    Join Date
    May 2000
    Posts
    80
    yes.
    Attached Files Attached Files
    pnj

  6. #6
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Wait, are you trying to use this code?
    PHP Code:
    var ButtonOne:ButtonOne = new ButtonOne();
    ButtonOne.100;
    ButtonOne.300;
    addChild(ButtonOne);

    ButtonOne.addEventListener(MouseEvent.MOUSE_DOWN,startMC); 

  7. #7
    Member
    Join Date
    May 2000
    Posts
    80
    I used that bit of code just to try and get the button to do what I wanted. That code works, but I'm curious as to why the simpler version doesn't?

    Why can't I just use the button instance that is sitting on the stage? It seems that the only way I can make this work is to use the code you're asking about.

    hope that makes sense..
    pnj

  8. #8
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    You have the clip on stage and in the library set to export for actionscript (which will cause the error). If you want to have the clip sitting on stage and assign actions then you have to assign the "Instance name" and not export it for actionscript.

  9. #9
    Member
    Join Date
    May 2000
    Posts
    80
    very nice.

    I'm a dummy. I wasn't giving the instance a name.

    Thanks.
    pnj

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center