A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] AS3 - Trigger Multiple Movieclips, Return its corresponding value/name

  1. #1
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971

    resolved [RESOLVED] AS3 - Trigger Multiple Movieclips, Return its corresponding value/name

    Hi buddies

    Any AS3 programer can show me the way of making this possible in AS3?

    Trigger multiple movieclips:

    PHP Code:
    var Amount:Number 5

    for (
    0Amounti++) 

    adder 1;  

    this["mc" adder].Num i
    this["mc" adder]._x * (this["mc" adder]._width 2); 
    this["mc" adder]._y 200

    this["mc" adder].onPress = function() 

    trace(this.Num); 



    I posted in the AS3 forum but no answers :P

    I tried

    var Num:Number;
    var Amount:Number = 5;
    var mc:mclip;

    for (var i:Number = 0; i < Amount; i++)
    {
    var adder:Number = i + 1;
    mc = new mclip();
    addChild(mc);

    mc.name = "mc"+ adder;
    mc.x = i * (mc.width + 2);
    mc.y = 200;
    mc.Num = adder;
    mc.addEventListener(MouseEvent.MOUSE_DOWN, Press);
    function Press (e:MouseEvent):void
    {
    trace(this.Num);

    }


    }

    But sniff sniff...it create the movieclips, but don't return its corresponding value... all the movieclips return "5" , the last "i" number of the for loop ... i read something abut "target" and getChildByName or getChildIndex but my eBooks don't want to talk to me they are angry at me hahaha!


    Thanks
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,785
    Hi,

    I assume you have 5 clips on the stage named mc1, mc2, mc3, mc4, mc5

    You can not change the name of a time line placed clip by the way.

    so mc.name = "mc"+ adder; would have thrown errors to see to start with.

    Maybe this will help you along
    PHP Code:
    import flash.display.*;
    import flash.events.*;

    var 
    Num:Number;
    var 
    Amount:Number 5;

    var 
    ClipArray:Array = [mc1,mc2,mc3,mc4,mc5];

    for (var 
    i:Number 0Amounti++)
    {
        var 
    Mc:MovieClip ClipArray[i];
        
    Mc.Num 1;
        
    Mc.* (ClipArray[i].width 2);
        
    Mc.200;
        
    Mc.buttonMode true;
        
    Mc.addEventListener(MouseEvent.MOUSE_DOWNPress);
    }
    function 
    Press(event:MouseEvent):void
    {
        var 
    mc:MovieClip MovieClip(event.currentTarget);
        
    trace("Num = " event.currentTarget.Num ". Name = " event.currentTarget.name);
        
    //addChild(mc);

    Last edited by fruitbeard; 11-09-2013 at 05:26 AM.

  3. #3
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Ok thanks.... i was about to say your code will not work , but then I realized I can make a for loop to push all the "mc" names into the array (mc1, mc2...mc40, mc50....etc) I already found (on saturday) the way of returning the movieclip pressed value, with the currentTarget, getChildAt and target methods. That was the detail i was missing. Thanks fruitbeard!!!!
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

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