A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] addEventListener(MouseEvent.MOUSE_DOWN, myFunction)

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    5

    resolved [RESOLVED] addEventListener(MouseEvent.MOUSE_DOWN, myFunction)

    hi

    i am making drag drop game.i create some movie clips dynamic.

    this is the code::

    recipesArray=["Steak","Chicken Panee","Bread","Fava Beans", "Jam"];

    /////Create Movieclips && set their text
    var mcArray:Array =new Array();
    for (var i:int=0; i<recipesArray.length; i++) {
    var mc:MovieClip = new MovieClip();
    mc.name = "mc" + i;

    mc.graphics.beginFill(0xFFE1C4);
    mc.graphics.drawRect( 0, 0, 150, 25 );
    mc.graphics.endFill();
    mc.x = recipeBox_mc.x + 25;
    mc.y = recipeBox_mc.y + 20+ (50*i);

    var t:TextField = new TextField();
    t.text = recipesArray[i];

    var tf:TextFormat = new TextFormat();
    tf.color = 0x000000;
    tf.size = 10;
    tf.font = "Arial";

    t.setTextFormat(tf);
    mc.addChildAt(t, 0);

    addChild(mc);
    mcArray[i] = mc;

    stage.addChild(mc);
    mcArray[i].alpha=.5;
    mcArray[i].mouseChildren = false;
    mcArray[i].buttonMode = true;
    mcArray[i].addEventListener(MouseEvent.MOUSE_DOWN, createInstant);


    now i want to know which movie clip is clicked .HOW????

    thanks in advance

  2. #2
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    You can reference it in the createInstant function as e.target, "e" being the MouseEvent parameter.

  3. #3
    Junior Member
    Join Date
    Dec 2010
    Location
    Hyderabad, India
    Posts
    3

    Thumbs up

    Hi

    You can get the current clicked movie reference with evt.currentTarget as given below

    function createInstant(evt:Event):void {
    trace(evt.currentTarget)
    }

    B.S www.flashankaractive.com | http://actionscript.flashankaractive.com

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