Table of sprite individual addEventListener

Hi, I ran into a problem of its too obvious or not many people meet because I can't seem to find a solution online!

The problem is I have table of sprite - 10 of them - and I need to save them all at a click event that changes color from black to white sprite.

However, I do not want to write:

a[1].addEventListener(MouseEvent.CLICK, change1);
a[2].addEventListener(MouseEvent.CLICK, change2);
a[3].addEventListener(MouseEvent.CLICK, change3);
... etc

Because they are all supposed to do the same thing (changing color from black to white), is there a way for me to use a single click event 'change' and at the same time know that click event demand comes from knowing that 'a', the user clicked?

Please help me!

I just assumed that you created your own class which extended the Sprite class, and you called it YourSpriteClass. In your case, your code should be:

c = new Array();
for (var i:int = 0; i < 10; i++)
{
    c[i] = new Sprite();
    c[i].graphics.beginFill(0x000000);
    c[i].graphics.drawRect(50 + i*20, 50 + i*20, 30, 30);
    c[i].graphics.endFill();
    c[i].addEventListener(MouseEvent.CLICK, change);
}

public function change(event:MouseEvent):void
{
    var source:Sprite = event.target as Sprite;
        //Code here!
}

You can also use

public function change(event:MouseEvent):void
{
    var source:Sprite = Sprite(event.target);
        //Code here!
}

The only difference is that the variable source in the first case will be nil when event.target is not a Sprite (like when you assigned the EventListener to something else, as well) and the second solution will throw a TypeError.

Tags: BlackBerry Developers

Similar Questions

  • Sprite will not respond to custom events

    I have a soft where many Sprite objects are placed on the stage, and then, when an event occurs (most likely mouse click), I want all of the Sprites to move around independently, based on an algorithm that has every Sprite.  I can't get the Sprite objects to respond to the event; I get no error, it's just that the right thing is not the case, see my comment below in red.

    Thank you!

    Here's my class of the event:

    package {}
    import flash.events.Event;

    SerializableAttribute public class MyCustomEvent extends flash.events.Event {}
    public static const = "deplaceza" CONTROL_TYPE:String

    public void MyCustomEvent (type: String, bubbles: Boolean = false, cancelable: Boolean = false) {}
    Super (type, bubbles, cancelable);
    }
    }
    }

    Here are my main:

    Import MyCustomEvent;
    import flash.events.EventDispatcher;
    import flash.events.Event;
    import flash.display.Sprite;

    var arr:Array = new Array();

    for (var i: int = 0; i < 10; i ++) {}
    var c:Sprite = new Sprite();
    c.addEventListener (MyCustomEvent.CONTROL_TYPE, doSomething);
    c.graphics.beginFill (Math.random () * 0xffffff);
    var myX:int = Math.Random () * 500;
    var myY:int = Math.Random () * 500;
    c.graphics.drawCircle (myX, myY, 5);
    addChild (c);
    arr.push (c);
    }

    function doSomething(e:Event):void {}
    trace ("Sprite heard event");  / / this does NOT
    }

    addEventListener (MouseEvent.CLICK, mouse click);

    function mouseClick(e:Event):void {}
    trace ("Click"); / / in this case
    dispatchEvent (new MyCustomEvent (MyCustomEvent.CONTROL_TYPE));
    }

    However, it seems based on the code you provided that it is not really as simple as that: that actually what needs to happen is that I have to visit each person individually and ship the order 100 times (your for loop).  Which seems to bulky me.  If they have the listener, why can't they just 'hear' my event a reshipment?  Which is not how things should work ideally?

    I think there could be a hundred ways in OO concepts to implement this functionality.

    I'll list some of them:

    1. Create a controller of empty MovieClip that will be the only object to listen to your event and move/scale or work on the required objects. [just like the model MVC]
    2. Create a class singleton as kglad told earlier and do listen to the object that will be internally "clone" of the event and send it to all your items. [just like the Singleton Pattern]
    3. Creates an array [that you use now], use no events rather directly move/scale or work on the required objects. [Simple OO]

    If you are looking for more on the design patterns on Google, you will get N number of styles available for you. I want to say OOP is not just about programming, it's more HOW YOU PROGRAM to thissubject. [because you will get thousands of ways to do the same thing.]

    Either by the way, I like your approach to learn things and it's very nice that you have not just copy paste the code ready to available employment.

    Keep learining going and happy!

  • both sets of criteria to fill the third table of research

    Hello-

    I'm very new to the numbers and support communities. I have read help and searched this forum but could not find a similar question. I appreciate any advice or suggestions.

    I created two table of numbers of our customer base and trying to treat it as follows: (see example below)

    Objective: Create a third table, which contains the invoice number, the date, the total bill and the State of residence, owner, as long the Bill IS NOT some elements of the Bill.

    In the example below, I've composed billing YES-POINT and POINT-NO; There are real elements in the database I want to search and do not take into account these bills that contain the element ITEM-NOT all together.

    Table 1 (total of the invoice):

    The Total State owner invoice # invoice date

    1                    12/1/15         $800.00                     NC

    2                    12/2/15         $125.00                     FL

    3                    12/5/15         $300.00                     NY

    4                    12/9/15         $500.00                     CA

    Table 2: (the individual elements that make up the invoice)

    Cost of billing invoice # point

    1 POINT-YES $200.00

    1 POINT-YES $100.00

    1 POINT-YES $500.00

    ARTICLE 2 - YES $25.00

    2 POINT-NO $100.00

    ARTICLE 3 - YES $300.00

    ARTICLE 4 - YES $400.00

    4 POINT-NOT $100.00

    The table of RESULTS based on the above would look like:

    Table results:

    The Total State owner invoice # invoice date

    1                     12/1/15           $800.00                       NC

    3                     12/5/15           $300.00                       NY

    Thank you very much for your advice and guidance.

    Put Hi,

    You wrote: ""as long as the invoice DO NOT include certain billsarticle.".

    But in your example, you showed two bills containing the same "some billing."

    In practice, will you be leaving bills that contains a specific item, or will you be leaving bills that contain one or more items in a list of several items?

    Kind regards

    Barry

  • How to create a PDF from a Web site with a java table?

    The table has three drop-down lists, which all lead to different tables on the Web site. I need a PDF of a lot of tables, combined or individually. Currently, the only way it works is to convert the page in PDF format after manually changing the drop-down list. I tried to go through Acrobat and creation of Web page for a page multilevel, but who comes to the menus overlap and still doesn't give me all the pieces I wanted.

    You can not convert the JS from a web page code to code that works in a PDF document

    file. They are simply too different.

  • How to revoke the SELECT on a table for a specific user?

    Environment:

    SQL * 3.1 on Windows XP Pro SP3 Developer to connect to Oracle 11.2.0.3 EE on Solaris 10.5.

    I have table T with SELECTION privilege granted on this issue both a role and a specific user.

    I am using SQL * Developer to revoke the privilege SELECT on this table of the individual user and leave the role.

    I can see how to revoke the role by right-clicking on the table and goes to the privileges-> revoke but I can't find where to choose a specific user to revoke of.

    Any help is greatly appreciated!

    -gary

    Hi Gary,.

    You are probably aware of the SQL syntax of base to make grant and revoke of SQL * more or the SQL Developer Worksheet:

    grant select on .T to ;
    revoke select on .T from ;
    

    To reach the equivalent to revoking of SQL Developer Connection Navigator...
    1. open the connection for
    2 expand the Tables node, and then open the object for table T browser.
    3. click on the grants tab and then, in its toolbar, select Actions->-> Revoke privileges
    4. Select in the drop-down list of the dialog box to remove user Action.
    5 shuttle privilege SELECT from the right back to the left, and then click apply.

    One would expect to be able to do the same thing from say the node under the node for the use of the SYSTEM for other users, but this isn't the case.

    Hope this helps,
    Gary Graham
    SQL development team

  • Tags for accessibility - what to do with the Table of contents &amp; more

    I'm looking for assistance and advice concerning the marking of a PDF document for accessibility using Acrobat 9 Pro.

    So far, the most I've ever done with Acrobat's create the occasional straight-text document and a few simple forms.  But my boss asked me to score a manual of programming for accessibility and I'm a little lost.  There are a lot of both the images and the code examples in this text that I have no idea how work with because auto-tagging is seems to be haywire.

    I downloaded the Acrobat 9 Pro accessibility repair Workflow document and have done the following:

    1. Determined that my document is not a scanned document.
    2. Determined that there are no forms or the buttons in this document.
    3. Set the language to English.
    4. Set security for document "no security".
    5. Determined that the document contains bookmarks.
    6. Determined that the document is not a document labeled.
    7. Run the accessibility full check.

    This is where I ran into problems - both because of the nature of the document and my own ignorance of the process 'make accessible '.

    My table of contents is divided into several areas indicated in the form of tables, but the individual elements of the array are improperly identified - I have no idea how to do to make them appear correctly.  Advice would be appreciated.  Suitable for the Table of contents even being a table?  I know it's called a table, but it has several levels and I'm not sure what to do with it.

    There are also several tables in the document.  They appear especially OK, but Acrobat seems to think tables are made up of individual and figures produced "No alternative text for Figure" errors on some of them.

    I mean, how the hell can I make text flow on code?  The code is all text, not images.

    If someone knows something about this whole thing accessibility I would greatly appreciate your comments.

    Thank you!

    Jenn

    Assuming that the original manual is the WORD, it is probably best to simply go back to WORD and PDF Maker allows you to create the PDF file. Which will add bookmarks and other tags which will provide accessibility. Probably all that is needed. It is much easier to create your own tags. Of course, I guess you use style sheets in the original and this marking would be. If you have not used the style sheets in the original, you probably have a lot of work in front of you.

  • Table and cell borders

    I use CS4. I created a table style in my stylesheet that calls for an orange 2 px wide border. The border only described the entire table, but not individual cells. Anyone know how I can fix this in the stylesheet?
    The URL is http://www.virginiacpac.org/pages/conference.html
    Thank you

    Hello

    Try this:

    {.table_border}
    border-collapse: collapse;
    }
    .table_border td {}
    border: 2px solid #E2832F;
    padding: 2px;
    }

    Take care
    Tim

    "dlipscombe" wrote in message
    News:giekco$BQJ$1@forums. Macromedia.com...
    > I'm using CS4. I set up a table style in my stylesheet that calls for a 2
    > px
    > orange wide border. The border only outlines the entire table but not the
    > individual cells. Anyone know how I can fix this in the stylesheet?
    > The URL is http://www.virginiacpac.org/pages/conference.html
    > Thank you,
    >
    > .table_border {}
    > border: 2px solid #E2832F;
    > padding: 2px;
    > }
    >

  • Help: Click the number of the store to a different variable after each button?

    Hello guys! Thank you very much for all the great help you have given me! I'm here with another question and hope someone can help me. Thanks in advance.

    So, I have 18 variables uint, 1 & 1 textbox.

    I want to my setup function so that when the first value entered in the text box, and the user clicks btnSave: 1st number is saved to var1.

    When the second value is entered in the text box, and the user clicks btnSave: the 2nd value is recorded as var2. and so on! I don't know you guys make the point.

    Example:

    3 is entered in the text box, the user clicks btnSave: var1 = 3, afterwords 4 is entered in the text box and btnSave is clicked: var2 = 4

    Thank you!

    In your event handler function, you can use the notation of support to store variables with names numerically sequenced.  An alternative would be to store the values in a table instead of individual variables.

    variable approach...

    var varNum:uint = 1;

    btnSave.addEventListener (MouseEvent.CLICK, saveValue);

    function saveValue(evt:MouseEvent):void {}

    This ["var" varNum] plus uint (textBox.text);

    varNum += 1;

    }

    approach to the table

    var vars: Array = new Array();

    btnSave.addEventListener (MouseEvent.CLICK, saveValue);

    function saveValue(evt:MouseEvent):void {}

    VARs.push (uint (TextBox.Text));

    }

  • Drag and drop the element of the array of Clusters

    I have a project that includes an array of 'tests', each of which is a cluster that contains an array of 'numbers', a matching the regular expression string and an array of "tasks" (all of them, is in turn, a group of elements).

    It is:

    • Tests (table of):
      • Cluster:
        • Reference numbers (an array of strings)
        • Regex (string)
        • Tasks (table of):
          • Cluster:
            • Task type
            • Basic channel,
            • Measuring channel
            • Other channels

    I wish I could drag and drop to rearrange the task table in an individual event.  (It is a nice-to-have rather than a urgent request - more for my own learning that no matter what).  For now, I've implemented "Move up" and "Move down" buttons

    Examples are fine for a single cluster that includes a table or an array of objects.  As soon as we have an array of clusters, it is difficult to access individual items within a specific cluster.

    Who that it be completed can drag and drop into such a facility?

    Curiously,.

    Geoff

    Hello GeoffF,

    It's certainly doable and you can even use the standard start drag and drop methods/events, the trickiest part is to determine the table of the elements that are selected on the mouse towards the top/mouse downwards and the swap of manual handling.  Fortunately, there are a few decent examples of how do this out there already, I suggest you take a look at this one:

    Example of community: determine the Index of the clicked element Array in LabVIEW

    https://decibel.NI.com/content/docs/doc-22434

    That should give you the selected table indexes, and then all you have to do is to move the elements around around the drop event.  I have attached a very basic demonstrative example that uses this code I just linked (you need to download that as well) and the events referred to swap two elements of the array.   The attached code is just thrown together, you'll want to design something more robust and scalable to any sort of actual use.

    Kind regards

  • How to fill a control ring with chains [] array?

    How to fill a control ring with chains [] array?

    It must be karma. (Try really bad karma because I couldn't post this question in my original)

    I must have been a Really bad guy in a previous life...  It's not like I'm bad in this one...

    So... what I want to do this time around?  Something that I thought would be easy... Well... it's a long story...  I had a simple solution, but the client wants something else.  -sigh-

    Here is what they want...  They want a control that allows for multiple selections to a control of the ring (or a control that allows a drop down selection menu).  Bites are filled at run time because it is based on 10 000 other precedents of things this particular choice.  So it must be dynamic.

    The snippet of code & images below show what I'm doing a little...

    The bottom image shows on the right bites which is filled in the control of the ring.  Since the number of items / items changes, I didn't have a bunch of controls stacked on another.  In addition, I have to deal with an unknown quantity of selections.

    Does anyone have a solution that can be recommended?  If so, can you share the solution / idea?

    Thank you

    RayR

    I have posted a code that does something similar here: http://forums.ni.com/t5/LabVIEW/array-of-cluster/m-p/1822451#M625032

    It uses a table hint and individual controls that are moved on top of the table and populated as needed.  This approach might work for you?  You would need a two-column table and only control ring, which you would fill properly whenever the currently active cell changes.

  • With an average of a spectral waveform and view / save

    Hello world!

    I am currently on a University project that consists on the use of Labview to obtain data and spectra of atmospheric plasmas using a spectrometer Ocean Optics HR4000.

    After not not using Labview for almost a year, I managed to get most of my knowledge back and I managed to display the spectral waveform, that I expect to get. However, as this is a fairly simple design I get a lot of noise and I would on average it for a graphic display more smooth.

    I looked into a lot of messages from the forum, but I couldn't really find what I was looking for.

    I also had a problem when you try to save the data and Spectra: I can't find anything in the directory of my VI.

    In the attachment you will find the current VI I'm trying.

    Thanks in advance for your answers!

    Jeremy

    I wrote an example for you below. This is an excerpt from VI, so you can drag the .png in your diagram and it becomes code. Pretend that everything in the green box is your Subvi spectrum acquisition.

    -Place the Subvi in a loop to run as many times as you like on average there

    -Out of the loop For is a table 2D with individual spectra on the lines

    -Transpose output, so individual spectra on the columns

    -Enter the table another loop to take the average rank by rank (with an average of different Spectra togeter).

    -Output is 1 d spectra average table

  • Boolean values of multiple digital inputs

    Hi guys,.

    It must be really basic but I looked around to find a solution with no success...

    I have a digital input with multiple-entry device.
    For example, I read signals 0-24VDC of pushbuttons and limit switches.

    I would just like to be able to assign to each entry to a Boolean to use anywhere in the code variable.

    Example: I install the DAQ help and get the usual result of 'data '. I'm guessing that this generates a table of Boolean signals.

    How to convert this table in a single Boolean DI signal for each entry?
    Or better yet, is there a VI I should use that emits individual signals?

    I also have the same problem for outputs digital. I'm guessing that I'll be able to apply the same principles to the problem well.

    Sorry if this is obvious and my thanks for the help.
    Joel

    Index table will collapse a table into individual elements.

    Build table opposite taking individual values and build in a table.

    I recommend you watch the LabVIEW tutorials online
    LabVIEW Introduction course - 3 hours
    LabVIEW Introduction course - 6 hours

  • event.localX of a MovieClip regardless of any other DisplayObject over/under/inside

    Here is an example:

    var table:Table = new Table();
    stage.addChild(table);
    //table covers the whole stage
    for (var i:int = 0; i<= 10; i++){
      var book:Book = new Book();
      book.x = Math.random() * stage.stageWidth;
      book.y = Math.random() * stage.stageHeight;
      if (Math.random() < .5){
        stage.addChild(book)
      }
      else {
        table.addChild(book)
      }
    
    stage.addEventListener(MouseEvent.CLICK, clicked); //notice that the eventListener is added to the stage
    
    function clicked(event:MouseEvent){
    trace(event.localX, event.localY);
    }
    
    
    

    what I need here, it's the localX or locally TO THE TABLE, not another thing.

    so the general question is "how to return event.localX of a certain MovieClip regardless of any other DisplayObject over/under/to inside it, without defining the mouseChildren to false (which I need to be enabled).

    This question is another discussion I had on actionscript 3 - event.localX of a MovieClip regardless of any other DisplayObject over/under/inside - Stack Overflow

    function clicked (event: MouseEvent) {}

    var globalPt:Point = new Point (event.stageX, event.stageY);

    var tablePt:Point = table.globalToLocal (globalPt);

    trace (tablePt.x, tablePt.y);

    }

    SOLVED

  • RAID 5 Powervault NX300, adding a drive

    I'm trying to add a disk to a RAID5 to the foregoing for capacity expansion. It has an adapter PERC H700.

    The answer verified in another thread here for what seems like I'm trying to do is:

    «You can use OMSA... go in storage, PERC, virtual disks and select Reconfigure in the drop-down list of tasks available for your RAID 5.»

    Well, I have the reader installed, it appears in physical disks in OMSA, with others in my table, but reconfigures isn't a choice under available tasks.

    I have 2 virtual drives, maybe that is the question? Both have options: delete, consistency, Assign/Unassign Dedicated Hot Spare, Blink and Unblink, Rename, change policy, slow initialize initialize quickly, replace Member disk.

    Anyone have any ideas? Thank you

    ffwalsh

    «You can use OMSA... go in storage, PERC, virtual disksand select Reconfigure in the drop-down list of tasks available for your RAID 5.»

    Well, I have the reader installed, it appears in physical disks in OMSA, with others in my table, but reconfigures isn't a choice under available tasks.

    RECONFIGURE is an option under drives VIRTUAL, not physical disks: you apply this operation in the table, not the individual disks.

    You have two virtual disks configured on the same set of disks? It's called "cutting", and Online Capacity Expansion will not work if you have slices RAID configured on a disk group. You will need to do a backup/restore or remove the second VFD, expand, rebuild, restore.

  • Copy the layer properties

    Hi all

    I had this frustration some time and thought there was nothing I can do about it as I don't want to buy a script just for this, if this is the case, but that's.

    If two layers are both 100% scale, but a single layer is 100 x 100 px, and the other is 200 x 200 px, is it possible that I can make one match on the other?

    I know that you can transfer the parent, but that seems to only affect that ladders, etc., I want especially to use it in the way I have a form for a piece of the video to go, normally a vector from illustrator as a placeholder, I don't then want to copy the shape and the parent to this.

    Is this possible?

    Thanks for any help!

    Expressions can return the height and width of a layer. You can write an expression that divides the target layer height and width and the width by the height of the source layer. There are two ways to write this expression. One using a table, one using individual values.

    This is option 1:

    sLayer = [width, height]; source layer

    tLayer = [thisComp.layer("target_layer").width, thisComp.layer("target_layer").height]; target layer

    [tLayer [0] / sLayer [0], tLayer [1] / sLayer [1]] * 100

    Here are 2 option:

    tlWidth = thisComp.layer("target_layer").width;

    tlHeight = thisComp.layer("target_layer").height;

    slWidth = width;

    slHeight = height;

    SX = tlWidth / slWidth;

    Sy = tlHeight / slHeight;

    [sx, sy] * 100

    Apply expressions of the scale property of the source layer. The outside dimensions of the source and the target will be now. If the layer 'target' is the parent that the source layer will react normally. If the source layer

    is the parent, you cannot adjust the pair scale without changing the expression with a value more than the statement. Here is an example of project CS6.

Maybe you are looking for

  • WiFi ERROR after update

    Hello everyone I'm not a resident of the United States and I bought this amazing phone I use the card Sim from Cellcom Israel I just see the update, the update firmware, run smooth but after reboot I try was to turn on the Wifi and we get an ERROR. T

  • Cannot use Z570 GT520m

    Hello I bought a Z570 for a customer and I can't choose to use video cards GT520m. The latest driver have been installed. but in the nvidia Control Panel, I can't change the video card from nvidia, and on the shortcut menu, the link: run with video c

  • my new construction with original hard drive, running 32-bit XP only loads in safe mode.

    I'M USING MY HDD TO MY ACER SA80 TOWER IN A NEW CORSAIR 800 D ROUND. MY MOTHERBOARD IS AN M4A785-M. RAM OF 4 GB COSAIR. THE HARD DRIVE has the XP 32 bit. IT IS SUPPORT OF SECURITY BUT NOT NORMAL BOOT MODE. DO I HAVE TO BUY A NEW OPERATING SYSTEM SO T

  • Office XP stuck in a loop of reboot in safe AND regular mode

    Randomly, one day, after that no new downloads or activities, when I started my computer it has crossed the first steps then says something don't like "Windows has encountered an error.  "Restart in the last mode which worked: normally, or in the saf

  • Smartphones from blackBerry Torch 9860 abandoned, what is the replacement?

    I contacted my provider to order a new phone for a new employee and told me the Torch 9860 was interrupted, and there is no replacement for it. Can someone shed some light on why this model was abandoned and if there will be a replacement for it?