detect clicks on multiple movieclips

Hello

Thanks for your time, read this.  I'm hard-pressed to find ways to detect clicks on various movieclips that I'm generation.   Basically, I am allowing to set a number any instances of the same clip.   I would like each instance A) be clickable and B) pass the reference to the click handler.

For example, I have something like this:

function addMissile() {}

this.attachMovie ("missile", "missile" + mtop, this.getNextHighestDepth (), {_x:startx, _y:starty});})

activeMissiles [mtop] = _root ["missile" + mtop];

.focusEnabled activeMissiles [mtop] = true;

Selection.setFocus (activeMissiles [mtop])

MTop ++

}

I would like to add a reminder on click for each of these instances of clip.   Grateful if someone can point me in the right direction

Best regards

Tom

You can use:

function addMissile() {}

var mc:MovieClip = this.attachMovie ("missile", "missile" + mtop, this.getNextHighestDepth (), {_x:startx, _y:starty});})

activeMissiles.push (this ["missile" + mtop]);

or better yet:

activeMissiles.push (mc);

mc.focusEnabled = true;

Selection.setFocus (mc);

mc.missileIndex = activeMissiles.length - 1;

mc.onRelease = function() {}

trace (this ._name + ":" + this.missileIndex);

}

}

Tags: Adobe Animate

Similar Questions

  • Detection of collision, multiple movieclips, auto collision.

    Here is my code to attach several clips on the stage

    var humans:Number = 90;
    for (i=0; i<humans; i++) {
              mcHuman = attachMovie("mcHuman", "mcHuman"+i, i);
    //blah blah
    }
    

    Whatever happens, it seems impossible to detect collisions between mcHuman and mcHuman...

    Anyone have any ideas?

    Thank you.

    There is probably more code that you realize that there are, but it is up to you to decide.

    Your first not set of loops make sense, just a loop is necessary as you had originally.  This might be a reason for things to go crazy.

    As regards the enterframe function goes, you have an excess of braces in this document, which could also be a reason for things to go crazy.  In addition, if you do not move humans at all (your code does nothing to move as it is), the you do not want or need the function enterframe no more...

    humans var = 90;

    for (i = 0; i

    mcHuman = attachMovie ("mcHuman", "mcHuman" + I, i);

    mcHuman._x = random (Stage.width);

    mcHuman._y = random (Stage.height);

    mcHuman.xTarget = random 20-10;

    mcHuman.yTarget = random 20-10;

    }

    for (i = 0; i

    for (j = 0; j

    If (_root ["mcHuman" + i] .hitTest (_root ["mcHuman" + j])) {}

    trace ("hit!");

    }

    }

    }

  • How to select and move more than one bookmark at a time? Shift + click selects multiple items that are next to each other in a list, because the element

    How to select and move more than one bookmark at a time?
    Shift + click selects multiple items that are next to each other in a list, because the items open in firefox before that happens.

    Glad it worked for you. Thanks for posting back.

  • Detect click trackpad

    Hi, I detect a click on the touchscreen with TouchEvent.DOWN

    but is there a way to detect a trackpad/trackball click event?

    Thank you in advance!

    Too bad! I found the solution!

  • Detect click button close a projector

    Hello world

    My name is Vijay, the India. I used to work with Director MX some time ago, but now had the opportunity to reignite the flame again. I just wanted to know how we can detect that a user has clicked on the close button of the projector. What is the technique for this? My idea is to display another screen just before the projector close to the BONE. I don't expect someone to write the code, but ju

    If you run MX2004 or higher, you can set the real exitLock and be notified of click the closeBox in the Manager "on closeRequest": CloseRequest - Director Online Wiki

  • How to drag and drop multiple movieclips at the same time

    Hello world

    I'm a new actonscript 3 and adobe flash CC user and I am building an application but I have been stuck for several days. I have looked everywhere and tried everything I could think of, but I can't yet find a solution to my problem that I thought were pretty basic.

    Basically, let's say I have a rectangle and a circle on the stage. Once I did of the movieclips and assigned an instance name to each of them, I want to be able to perform a drag and drop the Rectangle so that both the rectangle and the circle become movable at the same time.

    For now, I have a mouse down events listener associated with the instance of rectangle, a method startDrag assigned to the rectangle instance and another assigned to the circle. But in this configuration, when I click on and drag the rectangle, only the circle is mobile (only the last line in the code is taken into account).

    I don't know if what I'm trying to achieve is feasible, but any help will be greatly appreciated, thank you!

    The startDrag() method can only work for one object at a time, so in your case the Treaty the last of them, designated the task.  This approach is to temporarily to plant the two objects in a container and then drag the container.

    rectangle.addEventListener (MouseEvent.MOUSE_DOWN, fl_ClickToDrag);  When I click on the rectangle

    var dragMC:MovieClip = new MovieClip();
    addChild (dragMC);

    function fl_ClickToDrag(event:MouseEvent):void

    {
    dragMC.addChild (rectangle);        move objects in the container
    dragMC.addChild (circle);
    dragMC.startDrag ();
    }

    stage.addEventListener (MouseEvent.MOUSE_UP, fl_ReleaseToDrop); When I release the mouse button

    function fl_ReleaseToDrop(event:MouseEvent):void

    {
    dragMC.stopDrag ();
    Rectangle.x += dragMC.x;         Adjust the positions of the objects to their new location
    Rectangle.y += dragMC.y;
    Circle.x += dragMC.x;
    Circle.y += dragMC.y
    addChild (rectangle);                 move back to the scene objects
    addChild (circle);
    dragMC.x = dragMC.y = 0;       reset the benchmark for the dragMC
    }

    All this stuff of repositioning in the Drop function is necessary because when you drag the container, the positions of the content are still on their original coordinates inside the container.  So when you drop them they will resume their x / y positions in their new parent, meaning they go back where they were.  Reposition them where they have been trained to take into account the change in the position of the dragMC.

  • Remove the eventlistener for multiple movieclips in a table

    Hi all

    Game scenario:

    I do a crossing road learning alphabet game. In the first level there are 10 alphabets tell of A J (movieclips) stand on one side of the road in a mixed random way. The player must move the alphabets (using the keyboard commands) in alphabetical order, so that it strikes at the entrance of a kindergarten and is removed from the scene.

    Situation-problem:

    If you click on the correct alphabet the player gets a positive score. And if the wrong alphabet is cliked, a negative score is given. This works well for the first alphabet, but, once the first alphabet hits its target and is removed from the scene, it does not work for the next alphabet since removeEventListener to the case the first alphabet code continues to work for the continuous alphabets.

    For eg., once the first alphabet "letA" is removed from the scene, and then when I click on "Letbs" that gives a score to both positive and negative. Positive note, since it is the next alphabet that must be clicked. Negative note, since the "wrongClick" table contains the movieclip 'Letbs', although it was intended for the situation, when "letA" was also present on the stage.

    Code:

    var wrongClick:Array = new Array (Letbs, THG, letD, summer, fall, letG, letH, letI, letJ);

    for (var i = 0; i < wrongClick.length; i ++) {}

    wrongClick [i] .addEventListener (MouseEvent.MOUSE_DOWN, negScore);

    function negScore(e:MouseEvent):void {}

    gameScore += pointsForMiss; showGameScore();

    wrongClick [i] .removeEventListener (MouseEvent.MOUSE_DOWN, negScore);

    }

    }

    Requested solution:

    Can someone please tell me how I can write code that, once an alphabet is removed from the scene, the method addEventListener for above of movieclips is completely removed and a new addEventListener starts to work for the rest of the alphabet which remain on stage.

    thnx in advance

    Kind regards

    Ginette tabriz

    run this code:

    for (var i = 0; i)

    wrongClick [i]. delete EventListener (MouseEvent.MOUSE_DOWN, negScore);

    }

    When the correct letter is clicked.  That is to say, in the correct letter listener function.

  • multiple movieclips and mutiple event management.

    Hi all

    I have several movieclips (image sequence), which I want to add (click and drag), mouseevent event (left and right arrows) to the keyboard and the zoom event (mouse wheel).

    I have this function for one mc (image sequence).

    Now, if I use this function, I have some problem with the call of the function of the same frame.

    It's

    If click on an other mc in frame 3 say, click on another function, it should continue to frame 3 only, not from the first image again.


    Help, please.

    Thanks in advance.

    I guess that shows the part where you vortag home discovered in a 360-degree mode?

    If so, do a global var on your root timeline:

    var rotationframe:int = 1; at the beginning of the application, all dirffernt images are sitting on frame 1

    You can access this var to anywhere inside any function of your application by calling:

    root.rotationframe

    now in the service which manages the rotation (lets say its your keyboard function) at the end (after you have moved the playback cursor), you ensure that you always set

    root.rotationframe = garage.currentFrame;

    and in the service that manages switching between images write you sth. as

    gotoAndStop (root.rotationframe);

    Be aware, you cannot simply use this code without adapt it to your specific needs.

  • gotoAndPlay multiple movieclips

    Im making a gotoandplay function. He plays 2 movieclips at the sametime, but after a few clicks his work stoppages.

    is there a way to fix this?

    And is it possible to play/stop an object in a movieclip another?

    sample

    mc_movie. One.addEventListener (MouseEvent.Click, One1);

    function one1(e:MouseEvent)

    {

    mc_movie.gotoAndPlay (100);

    mc_button.gotoAndPlay (100);

    }

    mc_movie. Two.addEventListener (MouseEvent.Click, Two2);

    function two2(e:MouseEvent)

    {

    mc_movie.gotoAndPlay (200);

    mc_button.gotoAndPlay (200);

    }

    mc_movie. Back.addEventListener (MouseEvent.Click, Back);

    function back(e:MouseEvent)

    {

    mc_movie.gotoAndPlay (1);

    mc_button.gotoAndPlay (1);

    }

    If your timeline movement happens to take you far executives where these domestic buttons do not exist, they could lose their event listeners - depends on if they also exist in frameworks where this code does not exist which could be reallocated.

  • Detect clicks on a datagrid

    Hello
    I have the following code...
    [code]
    <? XML version = "1.0" encoding = "utf-8"? >
    "" < mx:Application xmlns:mx = ' http://www.adobe.com/2006/mxml ' layout = "absolute".
    creationComplete = "initApp ()" height = "377" width = "572" borderStyle = "solid" > "
    < mx:Script > <! [CDATA]
    Import mx.collections.XMLListCollection;
    Import mx.controls.Alert;
    import flash.events.Event
    import mx.events.ListEvent
    Import mx.events.ListEvent;
    [Bindable]
    private var _xlcDP:XMLListCollection;




    public function initApp (): void
    {
    var xmlDP:XML =
    < data >
    < item = quantity of "Potatoes" name = "200" price = "2.50" > < / item >
    < item name = "Onions" quantity = price "400" = "3,50" > < / item >
    < item name = "Carrots" quantity = price "100" = "4.00" > < / item >
    < item = quantity of "Ginger" name = "400" price = "3.00" > < / item >
    < = "Eggs" quantity element name = "200" price = "3.00" > < / item >
    < = quantity 'Salt' item name = "400" price = "2.50" > < / item >
    < item = quantity of 'Sugar' name = "200" price = "2.50" > < / item >
    < item name = "Apples" quantity = price "300" = "2.50" > < / item >
    < item name = "Banana" quantity = price "40" = "4.00" > < / item >
    < item name = "Grapes" quantity = price "300" = "3.00" > < / item >
    < / data >
    _xlcDP = new XMLListCollection (xmlDP.item);
    } //initApp

    public function checkvalue (): void {}
    {if(Qty.Text=='')}
    Alert.Show ("enter the quantity field ', 'Application Error!'")
    }
    else {}
    var selectedtext:String =
    var t:Number = Number (qty.text)
    var f: Number = t * dgSource.selectedItem.@price
    pricedisp. Text = 'RM' + String (f);
    }
    }
    []] > < / mx:Script >


    < mx:NumberValidator source = property '{quantity}' = 'text' invalidCharError = "invalid characters".
    minValue = '2' domain = 'int' invalidFormatCharsError = ' only the numbers!
    lowerThanMinError = "field cannot have less than 2 RM' trigger ="{mysub}"triggerEvent =" click on "/ >
    < mx:Panel x = "10" y = "10" width = "553" height = "357" layout = "absolute" title = 'point Flex' calculating alpha = "1.0" >
    < mx:DataGrid id = "dgSource" dataProvider = "{_xlcDP}" editable = "false" = "true" columnWidth = paddingLeft liveScrolling '0' = '20' x = "10" y = "10" active = "true" width "316" = >
    < mx:columns >
    < mx:Array >
    "< mx:DataGridColumn headerText ="Item"dataField="@name "textAlign ="center"/ >
    "< mx:DataGridColumn headerText ="Quantity"dataField="@quantity "textAlign ="center"/ >
    "< mx:DataGridColumn headerText =" (RM per Kg) price "dataField="@price "textAlign ="center"/ >
    < / mx:Array >
    < / mx:columns >
    < / mx:DataGrid >
    < mx:TextInput id = "qty" editable = "true" x = "148" y = "171" width = "71" / >
    < mx:Label text = "Enter your quantity" paddingLeft = "20" x = "10" y = "173" / >
    < mx:Button label = "Submit" x = "227" y = "171" id = "mysub" click = "checkvalue ()" / >
    < mx:VRule x = "334" y = "0" width = "4" height = "317" / >
    < mx:TextArea = "346" x = "10" width = "173" height = "297" text = "this simple application calculates the price with quantities and gives you the end result" editable = "false" / >
    < mx:Label x = "10" y = "208" text = "point :"/ > "
    < mx:Label = "17" x = "230" text = "QTY :"/ > "
    < mx:Text = "52" x y = "208" text="{dgSource.selectedItem.@name}"/ >
    < mx:Text = "52" x y = '230' text="{dgSource.selectedItem.@quantity}"/ >
    < mx:Label = "15" x = "256" text = "New price :"/ > "
    < mx:Text = "79" x = "256" id = "pricedisp" enabled = "false" color = "red" / >
    < / mx:Panel >
    < / mx:Application >
    [/ code]

    So what I need is to detect if the datagrid control has been clicked, to warn the user to select a row before submitting it, I see that there is a class called ListEvent, but I am unable to use it, as the compiler says that I can not have another public key word (I just copied the code of aid)

    How to do?

    If nothing has been selected, the DataGrid.selectedIndex will be-1.
    Tracy

  • Referencing of multiple movieclips that have similar names of instance

    I have a player movieclip and six movieclips obstacle with the name of "obs1',"obs2"instances, up to"obs6 ". If the player hits one of the obstacles, the death of variable is set to true. The code I have so far is:

    If (hitTest (_root.obs1) | hitTest (_root.obs2): (_root.obs3) hitTest | hitTest (_root.obs4) | hitT's (_root.obs5) |) {hitTest (_root.obs6))}

    dead = true

    }

    Since if the statement is bad enough as it is, I wanted to know if it was possible to reference all movieclips with instance name 'obs' followed by a digit. In my view, that it's hooks, something like:

    hitTest (_root.obs [i])

    Can someone give me some advice?

    (I use Flash CS3 and ActionScript 2.0)

    for (var i: Number = 1; i<>

    {if (HitTest (_root ["OBS" + i]))}

    dead = true;

    break;

    }

    }

  • Simplify multiple movieclips early frame masking

    I am trying to simplify my code and save space in my control panel actions.  At the beginning of a new mount, I have several hidden clips (._visible = false) until I call so that they become visible later.

    This framework AS I will condense:

    MC1._visible = false;

    MC2._visible = false;

    Mc3._visible = false;

    ... etc.

    I have about 30 MC # movieclips.  Can anyone show how to shorten the code so all 30 mcs are hidden you enter the picture?  A table perhaps?

    Thank you.

    There is no need of an array, but you use array notation:

    for (var i: Number = 1; i<>

    This ["MC" + i] ._visible = false;

    }

  • a multiple movieclips class

    Hello

    Yet once I fell on the dilemma of having a class on a Movieclip a desire then to use the same class on another clip. He put on another library attached does not work. I tried to use a class that extends my class but that extends a class extended movieclip seems misleading in flash.

    Is there a clean way without reprogramming of my class to do? Or I copy my class several times with a different name?

    TIA

    The class for Content1 was Content1 and its basic ContentFader class. Same Content2 is class: Content2 and the Base of the ContentFader class.

    Then just to mix it up a little. I created a Content1.as file, but none for Content2. Everything works as I expect.

    I guess it's as all y ' All thought that the base class meant something other than what I think he means? If that were the case it should say DisplayObject or actually all the object.

  • Detect the direction of += MovieClip?

    Hello

    I want to know how if a movieclip is go += or-= ._y ._y


    Thank you.

    Without providing for it otherwise, you should always check if the current value of the FLF is higher or lower than the previous value of the FLF.

    I probably would prepare something such that I would have a variable assigned to tell me that the status that would put any time that I specify ._y += or ._y =

  • Realistic of the random movements of multiple MovieClips

    Hi here is my code:

    30 images/s

    var human = 30;

    hSpeed var = 4;

    for (i=0; i<humans; i++) {
         //attach movieclip with name "human"
         //give it a random x y position (there are now 30 scattered human MCs)
         _root["human"+i].onEnterFrame = function() {
              this._x += random(hSpeed); //Here is the 'random' movement of the Movieclips
              this._x -= random(hSpeed);
              this._y += random(hSpeed);
              this._y -= random(hSpeed);
                   //some more code
         }
    }
    

    Makes the jitter movieclips on, humans don't do that, I can't find a way to make their random movement still smooth, moving in a random direction for a few seconds (preferably a random amout of seconds), then to change direction - I found a way to do it but it does not work on individuals It works on all 30 movieclips, which means that all move in the same direction.

    Don't forget that the movement must be random for each individual movieclip, not all move in the same direction.

    Does anyone know how? Thank you

    If you want to maintain the movement in a random direction for some time, then you're probably better using code interpolation.  Generate interpolations for each object that moves them from their current position to some random in some random delays.  And have a listener that determines when the Tween is complete so that a new Tween is engaged with the new direction and speed (time).

Maybe you are looking for