can F,CS3,AS3 detect the movieClip instance name by mouse click?
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: can F,CS3,AS3 detect the movieClip instance name by mouse click?

  1. #1
    Junior Member
    Join Date
    Jun 2004
    Location
    Kwait
    Posts
    21

    can F,CS3,AS3 detect the movieClip instance name by mouse click?

    Code:
    import flash.events.MouseEvent;
    //
    stage.addEventListener(MouseEvent.CLICK, reportClick);
    function reportClick(event:MouseEvent):void
    {	
    	trace("movieClip Instance Name = " + this.event.currentTarget.name);	
    }
    i do have on stage some movie clips that already given instance names .... "shape_01" , "shape_02" , ... "shape_50"

    i am looking for some thing like:

    1- user click on any shape
    2- flash detect that shape instance name
    2- flash store that name in a variable to be used later.

    END


    thanks in advance

  2. #2
    Junior Member
    Join Date
    Jul 2007
    Posts
    1
    Hi
    I had similar problem in Flash 8 and I solved it like this:
    Code:
    movieClipInstanceName.onRelease = function{
    var someVar:String = new String(this);
    }
    This returns the full name of the movie clip instance name!
    It's not for CS3, but I hope the idea is same and it will work for you!

  3. #3
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    event.target is the object clicked

  4. #4
    will i ever get it?
    Join Date
    Feb 2004
    Posts
    707
    senocular- sorry, but why? i would have guessed the first also..,.

  5. #5
    Junior Member
    Join Date
    Jun 2004
    Location
    Kwait
    Posts
    21
    senocular:
    thanks ... that did take it .. as i was planning ;]

    alchemist_bg:
    thanks .. but it was AS3 :]

    mlecho:
    thanks also for being here

    it is now like this:
    Code:
    import flash.events.MouseEvent;
    //
    stage.addEventListener(MouseEvent.CLICK, reportClick);
    function reportClick(event:MouseEvent):void
    {	
    	trace("movieClip Instance Name = " + event.target.name);	
    }
    Last edited by albisher; 07-18-2007 at 12:53 PM.

  6. #6
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    Quote Originally Posted by mlecho
    senocular- sorry, but why? i would have guessed the first also..,.
    event.target is the origin of the event. If you click on a shape on the screen (that is clickable) that is what event.target will be and it will remain that shape for all event handlers that handle the event throughout its propagation.

    event.currentTarget is the current object handling the event. This can be either the event.target or any parent objects for the target as each of its parents receive the event through propatation. For events that don't propagate, event.target and event.currentTarget will always be the same. event.currentTarget also matches the object from which you used addEventListener.

    So you can add an event listener to root and then click on a circle in root and the event handler listener will be passed a MouseEvent event object whose target is circle and currentTarget is root - circle is what was clicked, and root is the object now handling the event (from which addEventListener was called). root got the event through propagation.

    For more, read:
    http://www.adobe.com/devnet/actionsc...dling_as3.html

  7. #7
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,794
    import flash.events.MouseEvent; doesnt work for me.

    I get :

    'flash.event.MouseEvent' could not be loaded.

    I tried this too with same error:

    import mx.event.MouseEvent;

  8. #8
    Member
    Join Date
    Jul 2006
    Posts
    43
    did you put the code inside a class?

    if not that line is not needed.

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

Poll by Flashkit.com