A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: button inside movieclip problem

  1. #1
    Italy Novik2000's Avatar
    Join Date
    Jun 2001
    Posts
    360

    button inside movieclip problem

    hi,
    i have a button inside an MC,
    when i try to do :
    code:

    on(release)
    {
    trace(_parent.myMC._name);
    }



    i got "undefined".. why my button dont recognize his _parent as the MC?


    (i attached sample file)
    Attached Files Attached Files
    Last edited by Novik2000; 06-02-2010 at 04:12 AM.

  2. #2
    Senior Member
    Join Date
    Feb 2001
    Location
    On the fifth floor.
    Posts
    1,202
    code:
    on(release){
    trace(this._name);
    }


  3. #3
    Italy Novik2000's Avatar
    Join Date
    Jun 2001
    Posts
    360
    really? wheeew...

    and what if i need to get the pointer of the button itself?
    any other cases i would use "this"... what about this case?

  4. #4
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    You can get a reference to the button inside a button event handler by using this.buttonname (assuming the button is named).

    Also, in event handlers that are setup from frame scripts (as opposed to scripts attached to movieclips or buttons), this does still refer to the button - these scripts are handled more uniformly.

    The numerous little differences in syntax between frame scripts and movie-clip/button scripts are an endless source of confusion for folks here.

    Now some opinion:

    The main reason for using buttons (as opposed to movieclips) is when the button GUI (how the button graphically responds to rollover and clicking) is really simple and you don't need to refer to the button from a script.

    If you're doing anything remotely complicated, use a movieclip instead of a button - then this will refer to the thing you are pressing (the 'button') and this._parent will refer to the thing it is attached to.

    In my own code, I've pretty much abandonded the use of buttons entirely.
    Last edited by jbum; 10-11-2004 at 05:15 PM.

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