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!

Tags: Adobe Animate

Similar Questions

  • iTunes will not respond on Macbook Pro

    My iTunes will not respond when I hit the play button. My version of iTunes is 12.4.1.6. It worked when I bought my mac, but now, he won't answer. It works on my iPhone, but not my Mac. Any suggestions?

    iTunes you know on a Mac does not run on an iPhone. It's a completely different operating system. It is also a completely different application that Apple in a fit of lack of creativity has given the same name as the thing on a computer, but it's a different function.

    You have restarted your computer?

  • My Muse site will not display the customized html images that work in chrome?

    My Muse site will not display the customized html images that work in chrome? Here's my url www.simplesites.com.au.

    Works fine here on Linux.

    Note that the uploads has 'ads' in name and come from simplesites.net.au, so be sure that content blockers not get triggered.

  • With Firefox my fonts e-mail decreased and will not respond to reset, but problem goes away when you use Explorer

    With Firefox my fonts e-mail decreased and will not respond to reset, but problem disappears when you edit from Internet Explorer. This happened with no incentives from me about two weeks ago, and no resets respond to the email. Occurs only with Fox. With ie I enlarged and adjustable policies.

    Have you tried to resize the text size by pressing CTRL and + at the same time (increase font size)?

    Otherwise, you can reset Firefox on its default settings by following the steps here: https://support.mozilla.org/en-US/kb/reset-firefox-easily-fix-most-problems

  • Satellite Pro L450D black screen and will not respond to any keys

    Hello

    My niece has used his Toshiba L450D for almost a year now and he really liked it, who was until last month. She turned on her laptop and when she presses the button of the mouse, the button cracked and he fell into the laptop.

    Now my brother contacted Toshiba and I was told because it is under warranty it might return for repair because it was a common fault. Then he he packed in loads of air bubbles and a box to make sure it was safe.

    A few weeks later he came back repaired but we were all shocked that the laptop was put in a very loose box and you could hear this rattling noise. When we turned on the battery was flat and we had a new boot menu.

    As she installed it Windows 7 laptop would boot directly into Windows 7, but now after the repair of the laptop shows a menu black screen with as follows:

    + Windows 7 +.
    + Recover Windows to Factory Settings [active EMS] +.

    So we started in Windows and everything went well, but now after 5 or 10 or even 20 minutes, laptop displays a black screen and will not respond to keys or mouse movement. There is nothing on the screen its just black.

    I started in SafeMode (which was more difficult with the new menu) and it does the same thing. I even managed to do a virus scan quick who took 3-4 minutes and was clean.

    I would like some advice on what my niece is very angry, and it's difficult to explain what is happening to a child in the primary school.

    Any help would be grateful.

    Hello

    Have you tried the option of HARD drive recovery?

    If this is not the case, try to set the notebook back to factory settings using HARD drive recovery.
    Turn on the device, press F12, choose repair my computer, then select Toshiba HDD recovery.

    I hope it will work!

  • Windows XP will not respond to the keyboard or the mouse. Why it is not working.

    Well, I have the version of Windows XP Home Edition-32, Service Pack 2. I bought a keyboard gear yesterday with a mouse optical usb Dynex. My old keyboard and mouse were completely irreparable; I threw the. I plugged my new usb devices. When Windows has finished loading need me for my logon screen. However, my mouse and keyboard will not respond. This prevents me from going further. In addition, they will not respond during startup, the BIOS or the Windows Advanced Options Menu. I don't have a recovery disk. I bought the computer with XP already on this subject, so I do not have the disk to the operating system. What is my next step?

    I bought PS/2 devices, and they work perfectly. Thanks for the tip.

  • I am not able to browse the network. The workstation services and control of browser will not start. The event log shows the workstation service terminated with error code 2250.

    Internet, not able to browse computers on the network

    The computer has internet access, but I am not able to browse the network. The workstation services and control of browser will not start. The event log shows the workstation service terminated with error code 2250. Also in the event log Workstation reports: could not load RDR device driver. Cannot run the sfc in safemode, gives the 0x000006ba error, the rpc server is unavailable. Runs under normal windows, noticed in the registry last run: 0x000003e3 error code (try adding c:\windows\system32\drivesr\i81xnt5.sys to the dllcache)

    I'm puzzled.

    Hello

    I suggest you to send your request in the below link.

    http://social.technet.Microsoft.com/forums/en-us/itproxpsp/threads

  • Outlook express opens but will not respond to anything I try to do

    Outlook express opens but will not respond to anything I try to do

    You may have a damaged identity especially if it's the default main identity. File | Identities | Add the new identity. Create a new one and try it. If all goes well, you can import your messages and address book from the old identity and delete it.
     
    Note: Do not use the main word in the name of the new identity.
  • I have a Dell dimension running XP and IE8 will not respond

    I have a Dell Dimension 4500 XP pro and IE8 will not respond.
    When I click it it flashes up on top of the screen and disappears. To this effect, I can't watch the updates from Microsoft.

    Any ideas, anyone please?

    Delete.

    Hi guys,.
    It seems that my problem is solved.
    I removed a lot of the years of updates then run my drive setup and turned off and went to bed.
    When I turned on this morning I had to install updates. It was the only thing I was worried, and as this seems to be fixed, I am glad I use Firefox as my browser.

    I installed Speccy and he ran and it shows as running windows updates and it works correctly.

    Thanks a lot for all your help guys.

    Delete.

  • How can I get the "network" icon in the taskbar? The box of 'network' in the bar of tasks and Start Menu Properties; Notification area; System icons, will not respond to what it is.

    How can I get the "network" icon in the taskbar? The box of 'network' in the bar of tasks and Start Menu Properties; Notification area; System icons, will not respond to what it is.

    Use this tutorial:

    http://www.Vistax64.com/tutorials/106787-notification-area-system-icons.html

    Go to method 3.

    3. for the network icon.

    (B) to activate the icon network - Enable_Network.reg< click="" to="">

    * Don't forget to restart to complete the procedure. ***

  • Can't connect, connection startup screen will not respond to mouse clicks or keyboard

    I do not have a DVD to boot from. I use a laptop (Acer Aspire 5610). The keyboard and mouse are internal.  Any suggestions at all? I tried the Safe Mode, Mode safe mode with guests hoping to type rstrul.exe, but never had the guest. He went directly to the display of connection with my daughter and my icons. I have added no new material.

    Separated from the:

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_vista-security/cant-login-login-splash-screen-will-not-respond-to/54da4727-b98c-436a-8D82-f31c3355f5fd

    Have you shot inadvertently carpet of mouse/keyboard. This can happen through the Fn key on some laptop models. Find the picture on the key Fn, should give a clue.

    You can borrow or buy a usb KB and mouse that you would at least pass by troubleshooting?

    Tricky

  • AutoComplete will not retain any customer number when you use online banking.

    Original title: semi-automatic seized problem!

    AutoComplete is on, but will not retain my customer number if you use my banking online as it used to, can anyone help please?

    Hi AlanFreeborn,

    1. what web browser do you use?

    2. did you of recent changes on the system?

    If you use Internet Explorer, you can try to reset IE and see if it helps.

    You can read the following article and try resetting IE.

    How to reset Internet Explorer settings

    Note: Resetting the Internet Explorer settings is not reversible. After a reset, all previous settings are lost and cannot be recovered.

    Hope this information is useful.

  • Start PC laptop Toshiba in safe mode, only displays black screen, will not respond to any commands.

    Hello, I recently tried to do an advanced start safemode, because when I tried to do safe mode by pressing F8 it would have not responded to the command. Then I did a MSconfig, lit manually in safe mode, so I can then restart and do a scan to search for viruses or hackers of air because he had a reason to suspect. Now, after the manual switch, when I rebooted all I get is a black screen. No logo, nothing. When I press the buttons for the controls at first upward, it beeps at me and that's it.

    Done, I have XP, not Vista, don't know if it makes much difference or not, but that's exactly what I did.

    Is went to start, click Run, type msconfig, went to the utility system configuration, general tab selected, then the system of services. Then selected drivers devices of loading at startup Safemode-minimal database, and then click OK. Then, the computer said I had to be logged as administrator for these changes to take place and to connect and make changes. I was already logged as admin. so I advanced and restarted the computer and that's when I got black screen, no splash screen, no logo, no cursor.

    I just read that I could have possibly messed up by not checking the VGA mode in order to be able to communicate in this mode, I don't know if it is correct or not.

    I have my recovery discs, I've tried this morning, following their directions and it will not respond to one of these orders either.

    I don't understand, why... it was working fine before I did it, but like I said I suspected a virus or a hijacker, but my Norton 360 and SuperSpyware nothing not detected in normal mode. That's why I tried to safe mode.

    Here is the vista forums

    Try the forums xp on the link below

    http://answers.Microsoft.com/en-us/Windows/default.aspx#tab=4

    Answers by topic

    Walter, the time zone traveller

  • SYSTEM WILL NOT RESPOND FOR 1 MIN AFTER THE CONNECTION

    Once connected to my system after a reboot it will not respond for atlesat 1 minute. I can open some software like firefox... but I can't open Control Panel or modify a system

    Hi mohdrafi,.

    (a) since when are you facing this problem? What were the changes to the system between the time where everything has worked, and when you noticed the problem?

    This problem may occur because of the conflict between the hardware or programs on the computer.

    To refine the question, I suggest you try the following steps:

    Disconnect all external devices, mainly USB devices except for devices such as the mouse and keyboard.

    Check if the problem persists,

    Step 1: Disable security software, follow the steps mentioned below

    http://Windows.Microsoft.com/en-us/Windows-Vista/disable-antivirus-software

    Note: Activate security software once the test is completed.

    Step 2: Start the computer in safe mode and check if the problem persists, to do this, follow the steps below.

    Access the menu advanced startup options by turning on your computer and pressing the F8 key before Windows starts. In the advanced startup options select safe mode

    http://Windows.Microsoft.com/en-us/Windows-Vista/advanced-startup-options-including-safe-mode

    If everything works properly in safe mode, you can deduce that some third-party services are at the origin of the problem.

    Step 3: Put the computer to boot to figure out program causing problem.

    Follow step 1 in the link below,

    How to troubleshoot a problem by performing a clean boot in Windows Vista or in Windows 7

    http://support.Microsoft.com/kb/929135

    If everything works well after a clean boot, you can deduce that some third-party services are at the origin of the problem.

    After find you the program that is causing the problem, you will have to perhaps to update or install a newer version of the program, if you rarely use that you should consider uninstalling the software

    Important: n ' forget not the computer to start normal follow step 7 in the link.

    For more information, see the link below:

    What to do if Windows does not start successfully

    http://Windows.Microsoft.com/en-us/Windows-Vista/what-to-do-if-Windows-wont-start-correctly

    This might interest you:

    5 ways to speed up your PC
    http://www.Microsoft.com/atwork/maintenance/speed.aspx

    Thank you, and in what concerns:

    Ajay K

    Microsoft Answers Support Engineer

    Visit our Microsoft answers feedback Forum and let us know what you think.

  • CPU on HP p6130y will not respond unless I have unplug and reconnect.

    CPU will not respond unless I have unplug and reconnect.  The power light turns on but the screen remains black.  Monitor works.  Sometimes it will come around after a disconnect - reconnect.  This morning I had to unplug and reconnect six times before would respond to the computer.  HP model p6130y.  AMD Phenom 9750 Quad Core processor.  Windows Vista.

    23Scorpio wrote:

    Hi old_geekster and thanks for your reply.  I tried to find a site that has the power to my computer and I'm having no luck.  Same HP does not list that they carry the power supply for my p6130y.  You have no idea where I can get this?  Do you know how much it costs?  Thanks again.

    ___________________________________________________________________________________________

    23Scorpio, it's my pleasure.

    You should be able to use any standard ATX PSU in the computer.  I suggest to measure the current PSU and comparing measures that you choose.  I like Corsair and OCZ.  The PSU is the backbone of the computer, it is not the place to save money.  Both in the links I provided are good examples of what you can use.  Read the reviews to see what users have to say about them.

    If your problem is solved, please click "accept as a Solution.

Maybe you are looking for

  • Snow Leopard update to El Capitan

    I need to upgrade my imac of El Capitan of Snow Leopard desktop (end 2008) 10.6.8 version. Read these forums useful to get advice, I do not understand some of the info/advice. I've been deleting old files and currently have 10.5 MB of available stora

  • Bold and italic

    Hello This question must have been asked a million times, but I find no answers to him.  How can I select both bold and italic text when you type a formula in Safari? I'm writing captions on a Web site, but when I try to click on the fonts, bold or i

  • Errors in user profile on the server terminal server 2008 R2

    I have a problem on a Windows Server 2008 R2 SP1 running Terminal Server services with roaming profiles. The server works as a terminal server server for some time without any problems, but a few weeks ago he began logging on users with temporary pro

  • Catalyst Control Center

    I kept getting a message that wasn't the catalyst controller. UNON several suggestions I deleted the program, if it is bad to my computer.

  • Duration of still images

    In the first 14 elements, I can't change the length of the image more than 3 seconds.  The duration of the default image is 150.  I changed it to 180 and same 360, but when I add a photo, they run all 3 seconds, regardless of what's on the duration.