A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Multiple Movieclips Press

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

    Multiple Movieclips Press

    Hello guys, i am from the AS2 forum, now i'm introducing myself to AS3 to develop android apps

    So, I already achieved few things, Depths, addChild, listeners, etc. but now i'm stucked in something I do very well in AS2, it would be something like this:

    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 tried this on AS3, and searched on google and in this forum and no answers:

    PHP Code:
    var Num:Number;
    var 
    Amount:Number  5;
    var 
    mc:mclip;

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

    mc.name "mc"adder;
    mc.* (mc.width 2);
    mc.200;
    mc.Num adder;
    mc.addEventListener(MouseEvent.MOUSE_DOWNPress);
    function 
    Press (e:MouseEvent):void
    {
    trace(this.Num);

    }



    I achieved creating the 5 movieclips, and they all respond to the press, but all of them throws the Num variable "5" , the last "i" number of the for loop, and they are supposed to thow their corresponding number (mc1 = 1, mc2 = 2, etc)


    What am I missing? I have like 3 as3 pdf books and no explanation in this specific scenario. 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,780
    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);


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