How to add events to the array elements?

Hello.

I have the table with 5 boxes.

I show as boxes on the stage that + having shown that it is random.

Now, I want to add events to this boxes.

For example if I click for box1 I have to go to "p4", if I click to other boxes that I have to go to "p3".

I'm trying to do the same thing as for the buttons, but its does not work:

classNames[0].addEventListener(MouseEvent.CLICK, goCorrect);
function goCorrect(event:MouseEvent):void {
     trace("p4");
     gotoAndStop('p4');
}

classNames[1].addEventListener(MouseEvent.CLICK, goWrong);
function goWrong(event:MouseEvent):void {
     trace("p3");
     gotoAndStop('p3');
}

All the code in the code here:

var classNames:Array=["box1","box2","box3","box4","box5"];
var boxesList:Array=[];
var ClassRef:Class;

for (var i:int = 0; i < classNames.length; i++) {
     ClassRef=Class(getDefinitionByName(classNames[i]));
     boxesList[i] = new ClassRef();
     addChild(boxesList[i]);
}

var currentBox:MovieClip;


var nextX:Number=0;
for (var iii:int = 0; iii < classNames.length; iii++) {
     currentBox=boxesList[iii];
     currentBox.x=nextX;
     nextX+=currentBox.width;
}


for (iii= 0; iii < 1*boxesList.length; iii++) {
     var pos1:int = (Math.random()*1000) %boxesList.length;
     var pos2:int = (Math.random()*1000) %boxesList.length;

     if (pos1!=pos2) {
          var temp:int=boxesList[pos1].x;
          boxesList[pos1].x=boxesList[pos2].x;
          boxesList[pos2].x=temp;
     }
}

myBox1.visible=false;


classNames[0].addEventListener(MouseEvent.CLICK, goCorrect);
function goCorrect(event:MouseEvent):void {
     trace("p4");
     gotoAndStop('p4');
}

classNames[1].addEventListener(MouseEvent.CLICK, goWrong);
function goWrong(event:MouseEvent):void {
     trace("p3");
     gotoAndStop('p3');
}
//box1.useHandCursor=true;

You cannot add event listeners to the objects that send events. Generally speaking, an object that you want to send events should extend the EventDispatcher class.

In your case, you add event listener for the classNames group members that are strings. String not to send events. So, you have to add listeners to events for objects that you instantiate while loop if classNames - these items are (I presume that these are instances of MovieClip, which stretches from EventDispatcher). Therefore, in your case, you can do the following:

MovieClip(boxesList[0]).addEventListener(MouseEvent.CLICK, goCorrect);function goCorrect(event:MouseEvent):void {     trace("p4");     gotoAndStop('p4');}

MovieClip(boxesList[1]).addEventListener(MouseEvent.CLICK, goWrong);function goWrong(event:MouseEvent):void {     trace("p3");     gotoAndStop('p3');}

Tags: Adobe Animate

Similar Questions

  • How to add events at the bean of type Date

    Hello

    I created two date items - start date and end date.

    now, I want to add the event in these points?

    How can I add event at the bean type date?

    Pls help...

    Thank you
    Amit

    Hello

    Try code below

    Import oracle.cabo.ui.action.FirePartialAction;

    FireAction firePartialAction = new FirePartialAction ("updatedate");
    StartDateBean.setAttributeValue (PRIMARY_CLIENT_ACTION_ATTR, firePartialAction);

    Thank you
    Pratap

  • How to add content in the xml element?

    I need to insert a word sqrt (plain text without tags) in the xml element of m:msqrt as below:

    enter image description here

    I tried,

         

    var path = (app.activeDocument.fullName.parent.fsName) m:System.NET.SocketAddress.ToString () replace (/ \ / g, ' /'); document path (sample.indd) active

    var xmlPath = (app.activeDocument.fullName.parent.fsName) m:System.NET.SocketAddress.ToString (.replace(/\\/g, '/')) + "" / with_aid2.xml ";"

    xmlFile = file (xmlPath);

    {if (xmlFile.Exists)}

    xmlFile.open ();

    var myString = xmlFile.read ();

    xmlFile.close ();

    myXml = new XML ();

    myXml = XML (myString);

    var msqrtCount = myXml.xpath("//m:msqrt");

    } else {alert (xmlPath + "does not exist!") ;}}

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

    var added = msqrtCount [i];

    added.contents = "sqrt";

    }

    I get an error indicates the invalid content property.

    Try this,

    var myDoc = app.activeDocument;
    mySqrtTag(myDoc)
    function mySqrtTag(elm)
    {
        for (var i = 0; i < elm.xmlElements.length; i++)
        {
            if(elm.xmlElements[i].markupTag.name.toString() == "m:msqrt")
            {
                elm.xmlElements[i].insertionPoints[0].contents = "sqrt";
            }
            mySqrtTag(elm.xmlElements[i]);
        }
    }
    
  • How to add items to the table

    Hello:

    I have a general question about powerCLI: How can I create table and add the object to this table later?

    Basically, I select all virtual machines, check something on them using "foreach" and "" matches a condition later with what I need I want to put it (vm) to the specific table ($vms) that I'll use later.

    How can I do?

    Thank you very much!

    Hello, qwert1235-

    You can use something like the following:

    ## initialize a new array$arrVMs = @()Get-VM | %{    ## if the VM is config'd with more than 4GB mem, add it to the array    if ($_.MemoryMB -gt 4096) {$arrVMs += $_}} ## end foreach-object
    

    But, really, you should be able to avoid the extra code and just do a table of elements you want from the outset, as:

    ## make an array of VMs config'd w/ more than 4GB mem$arrVMs = Get-VM | ?{$_.MemoryMB -gt 4096}
    

    There are times, however, when adding a table would be necessary.  The first example would do exactly that.

  • How to add text to the file selected?

    I have already updated title but I don't know how to add it to the selected real file (the one in the middle)... I read on some other forums but its still confuse me.  Also, is there anyway to add the effect of movement, as drag in or dissolve almost?

    Screen Shot 2016-02-19 at 10.27.40 PM.png

    I mean this in the nicest way possible, but it's very wacky workspace you put in place there. Create titles is muuuuch easier in the standard workspace Edition. When you create / open a title in the editing workspace, he creates a floating large window with the title of all the members of panels. It is about the only time I am ok with windows in the first floating. You will create the title in the window title, and then close the window title entirely. The video for the title will then be in your project Panel (which you can not common to see in your current workspace configuration, but will be very apparent in the workspace standard edition in the lower left). So the best thing to do is to simply drag the title element of the project to sequence Panel (another Panel today, you don't see in your current workspace arrangement.

  • How to add bookmarks to the IE Favorites list?

    How to add bookmarks to the IE Favorites list? I can find them on recently added bookmarks, but they are not listed when I click on IE Favorites.

    Firefox bookmarks are stored in your Firefox profile folder, they are not synchronized with the IE Favorites.

  • How to add programs to the start of the file using Vista

    How to add programs to the start of the file using Vista

    Hi Harry,.

    Oddly enough, you can actually do it in msconfig except if it is already there and simply not checked as opposed to not being do not at all (although you would think that they would understand this option).

    The easiest way is to add the program (or a shortcut to the program) in the folder all Menu Programs Startup.   Here is the procedure: http://www.ehow.com/how_5098465_add-startup-programs.html.  Remember, to do this, you must either a shortcut existing (perhaps on the desktop or elsewhere in the menu all programs) or you need to find the source file (probably somewhere in C:\Program Files depending on what you want to add) and either copy it and add it to the startup folder or right-click on it and create a shortcut to copy into the startup folder.  Once you reboot, this program starts during the initial commissioning process and you will now be able to control using msconfig.exe, if you wish.

    Another option is to do this by using the registry editor.  If you decide to try this, first create a restore AND system restoration point backup of the registry before you begin.  Here is the procedure: http://www.ehow.com/how_7304438_add-program-msconfig-regedit.html.  I recommend to use this ONLY if the previous procedure does not work for some reason any as long as that the procedure is simpler and safer.

    If you want a simpler way to manage and control startup programs, you can try it free WinPatrol http://www.winpatrol.com/download.html that change monitors for startup programs if you set it to run in real-time so that you know when to try new programs are added to your Start menu and, for the purposes of this question includes an Add button which opens a link to a window of Windows Explorer where you can browse the program you want to add, click open to select and then add it directly to the commissioning.  If you prefer it does not work all the time, you can simply uncheck the box which includes this program and it will work only when you choose to run (but at the start, will work as an indication otherwise or configured).  It will appear not in the start menu in all programs (Finally, WinPatrol is, but not programs, it adds to the start), but it will appear in WinPatrol (which also lets you manage what you want or not start with checkboxes as in msconfig) and sure in msconfig - but only after a reboot is complete the process of adding.

    I hope this helps.  Personally, I use WinPatrol myself and let it run in real time.  Since I do a lot of installations, it helped me often prevent the addition of a startup item I haven't really need and reduces how many times I actually need to check what is happening out there.

    If this answers your question without the need to repost in another forum, please mark it as an answer.  If this isn't the case, then of course you must republish as suggested above.

    Good luck!

  • I want to print PostScript in illustrator, then put the Distiller how to add print on the list?

    I want to print PostScript in illustrator, then put the Distiller how to add print on the list?

    What exactly do you want to do it is not possbile to save to the PDF format?

  • How to add licenses in the VIP administration Console

    How to add licenses in the VIP Admin console?

    Hello

    Please see: -.

    Manage your cloud of Adobe Creative for the composition of teams

    Adobe Creative Cloud for teams FAQ

  • Cannot figure out how to "add-in" for the 2013 Outlook application... said the loading behavior is not loaded. How can I fix it?

    Cannot figure out how to "add-in" for the 2013 Outlook application... said the loading behavior is not loaded. How can I fix it?

    Hi amandab9126792,

    2013 Outlook does not work with Acrobat X because they are not compatible. Please check the compatibility to https://helpx.adobe.com/acrobat/kb/compatible-web-browsers-pdfmaker-applications.html.

    Kind regards

    Nicos

  • How to add text to the gif format

    Hello, I am a beginner in photoshop.

    I want to add text to my gif as part of the animation, but somehow the text transparent look, even though I already use black color for the text.

    Could someone give me tutorial how to add text to the gif and then do some sort of subtitle?

    Thank you...

    The text layer is 2 layers under the real background layer in your file. Check your layers panel. Click, drag and drop the text layer currently selected in your layers 2 screenshot above or the visible layers, especially to see if your text will appear - it should ideally.

    Settings - when save you for Web & devices, you can customize options preset for GIF on the top right of your dialog "save for Web & devices".

  • How to add text to the Notes?

    Hi all

    I want to add some text in the notes. I create notes with success.

    My note label and name are not apply any script executed successfully.

    How to add text to the note? My script is:

    indesign #target

    myDocument var = app.documents.add ();

    var myTextFrame = myDocument.pages.item (0).textFrames.add ();

    myTextFrame.geometricBounds is ['10', 15 ' p', '50 p', '50 p'];.

    myTextFrame.contents = "Adobe Indesign";

    var insertionPoint = myTextFrame.insertionPoints.item (-1);

    var note = insertionPoint.notes.add (1433299822);

    Note.label = "NewNote";

    Note. Name = "FirstNote";

    Thank you

    Jin

    try sth. like

    Note.texts [0] .silence = 'some content '.

    Hans-Gerd Classen'

  • How to add sounds to the light icons in the taskbar when events happening?

    Well, my question is maybe very simple, I hope I can get help here, I ve been wondering how to make the icons on the taskbar sound when something happens for example when you receive a message 'Skype', the light of the task bar, but in my case they do not all sound the answer to that might be in the Skype settings, but, I want is doing the actual windows to make a sound to tell me something that is happening there, and of course I can chose the sound of that.

    the example of "Skype" might not be the best here, lets say another software, when is reduced and something happens, call your attention to the icon in the taskbar with start to glow, but sometimes I'm in another place, or looking for another way I could not miss this event in this software need my immediately attention with sound, I could turn on my loud speakers so I will be heard.

    Thank you

    Hello Derwyn,

    Thank you for your response.

    I appreciate your time and your concern.

    Unfortunately, the desired Windows sound is not included in the Windows sound scheme.

    However, in the article in the previous post on changing the sounds of the computer, you can see under the heading 'Windows Explorer' under the window 'events of the program'inside'sound'. You can find the other sounds of Windows Explorer as blocked pop-up navigation block, empty, trash, move menu items and so on.

    Thank you

  • How to change the value of the array element by using the property node

    Hello all :)

    IM using a table in the drop-down list box. the size of the array is not fixed.

    I want property strings [] from the drop-down list box to enter text in selection, but since I placed it inside the table im unable to use this property.

    I used 'arrayelem' reference property and property node connected to it but got no strings [] in the selection.

    so is it possible that I can use property strings]


  • Change the value of the array element without using the keyboard

    I have a control array on my front, say 1 d, 10 items.

    In addition, the front panel should be used with a touch screen, so I have a Subvi keyboard that should be called when I choose one of the elements of the array.  Therefore, no keyboard entry is allowed.

    My question is, how can I determine which element that the user hit/clicked?... .and how to change this value?

    -Mike

    Gents nevermind, found a way to emphasise that if this is the best way, but I got it.

    In my structure of the event, I have an event looking for the mouse event down in regards to the control array.  This event triggers my screen touch keyboard Subvi to fire, and the closure of the Subvi I pass its value to the ArrElem.Value property to assign the table a hit/clicked item.  Works.

    -Mike

Maybe you are looking for

  • Automate the Terminal

    I need to enter 6 lines in the Terminal, whenever I want to use my sculptor. How can I do this? All I can find on the internet is how to say 'Hello World', useful? Maybe, but not what I need. I have zero coding experience. Thank you Scott export GOPA

  • WiFi stopped working

    We're both 73 years old so not savvy with laptops, etc. our wifi stopped working, but he works hard cable does anyone know what has happened and how we can fix it, please

  • the vaio l series upgrade to ssd

    I have a Vaio L series two year while a (VPCL229FG). I want to improve the internal HD 1 TB for an SSD or a hybrid SSD hard drive. Is someone doing a swap on the hard drive of a vaio L series all-in-one? all the instructions of opening and the size o

  • If I download the new version this will compromise the documents filed, I have in the old version?

    I need to download a more recent version of a document that I need to update.  However, I have several important documents deposited in the old version. If I download the new version it will compromise these elders?

  • Cannot install updates of work

    He continues to tell me in Windows Update I have to install this update and then attempt to install without an error-error code. Any other update isnatlled, but this one simply refuses to and I tried these last days to install several times.