Remove several children and raise an event if no child more?

I use for loop to display 3lifes on stage to help:

/////////////////////////////////////////////////////

for (var i = 0; i < 3; i ++) {}

var: life life = new life();

Life.x = 100 * i + 650;

Life.y = 20;

addChild (Life);

}

///////////////////////////////////////////////////

and I have already create a hitTestObject on the character when the character comes in contact with a movieclip, removeChild (Life);  is triggered. The first child deleted successfully, but when it comes to the second, an error pops up:

ArgumentError: Error #2025: the supplied DisplayObject must be a child of the caller.

at flash.display::DisplayObjectContainer/removeChild()

at _4_fla::MainTimeline/hitBoy() [_4_fla. MainTimeline::frame1:52]

at _4_fla::MainTimeline/dropEnemy() [_4_fla. MainTimeline::frame1:41]

What should I do to fix this? and how to trigger an event after that no more life is left?

1. Why do you not use import flash.events.Event;?

You wanted to send an event... So I sent the new Event(); If you use class come, you must import it, otherwise, you get a compilation error.

2. your Solution actually works, he removes my mistake and dead second and third without are the tips is to make individual addchild in an array?

The idea is to store references to your life in a table, so you can target as many lives as you wish. You have used only a single variable - life, which can only point to a single object.

3. I try to run:

removeLife();

  removeLife();

  removeLife();

for the third time, butYou have no more lives. doesn't seem to triggered in the output window?

Do you have addEventListener ("dropDead"...)? Use the method trace to print from lives.length:

4. when I run removeLife() for the fourth time, an error occurs?

TypeError: Error #2007: child parameter must be non-null.

Sorry, did not bulletproof. You should stop the game when you have 0 lives anyway, so this shouldn't happen. But try this instead:

// this function triggers when I'm supposed to lose life
function removeLife():void {
    if(lives.length == 0) {
        trace("What are you doing here? You should be dead already!");
        return;
    }

    var Life:life = lives.pop() as life;
    removeChild(Life);

    trace("You have still " + lives.length + " lives.");
    if(lives.length == 0) {
        trace("Baam! You're dead. Dispatching event.. 'hope somebody is listening.");
        dispatchEvent(new Event("dropDead"));
    }
}

Tags: Adobe Animate

Similar Questions

  • Define and raise custom events

    I am designing and building a library of reusable Cast that can be included in a variety of other Director projects. This library will provide an interface to joint Code readers barcode that appear as a keyboard on the computer and also provides interfaces for interacting with external software.

    My problem is finding how to set and trigger custom of this Cast library events. Currently I set him up in a Global Script within the library. However, all it seems I can do the script is call a predefined function that implemented the film container. He can't really have several event listeners.

    There are two events that I am trying to define and raise:
    1. the notification when a label barcode is scanned
    2. the notification when a server database search ends

    The typical application flow is that a film's Director parent will sit idle waiting for a TagScan event mode is triggered. After the TagScan event, a request is sent to a central server to retrieve the associated information in the barcode that has been analyzed. Because we don't want UI suspended pending data to return, there was an another event notification when data are available for use.

    So my question is really in two parts:
    1. is my approach to the use of a global script in an external library to Cast the best way to put in place a reusable module?
    2. is there a way to define and trigger custom since a global script events?

    Thanks in advance,
    Shawn.

    1. the best way to create reusable code is to use behaviors and parent scripts. Some 98% of your code should be one of these two types - not movie scripts.

    2. by "global script" I assume you mean a set of functions in a movie script. If so, then it is not a good approach.

    Here is the skeleton of how I would approach. A system of events at its basic level is nothing more reminders with an object that queries the status set up other objects. A reminder is when an object passes a reference on behalf of one of its names of Manager to another object. This allows the second object to make a call to the first object. When he made that call, belongs to the second object.

    What you need is an object that monitors stocks asynchronous data recovery and drive barcode from the server. Create a Parent script with the following code.

    -Barcode monitor

    property pEvents - list of events and the saved objects that is called when an event occurs.
    property pTimeOb - timeout object used for the periodic polling/verification of the status of various asynchronous actions.

    the new me
    pEvents = [#BarcodeScanned: [], #DataReady: []]
    pTimeOb = timeout () .new ("BarcodeMonitor", 200, #CheckAsyncStatus, me)-means "200" we check five times per second.
    return to me
    new end

    on addEventListener, CallbackObject, CallbackHandler, event - script instance, symbol, symbol
    -can add validation of argument here.

    CallBackInfo = [#CallbackObject:CallbackObject, #CallbackHandler:CallbackHandler]
    pEvents [Event] .add (CallBackInfo)
    end addEventListener

    on me, removeEventListener CallbackObject, CallbackHandler, event - script instance, symbol, symbol
    -code that walks the list and deletes all corresponding combinations object and handler for the specified event.
    end removeEventListener

    on CheckAsyncStatus me, Timeob
    -check the status of various asynchronous barcode things happening.

    -Callback sample
    -At this point, some data is ready and has been recovered
    Data = "everything data".
    EventCallBacks = pEvents.DataReady
    Repeat with CallBackInfo in EventCallBacks
    call (CallBackInfo.CallbackHandler, CallBackInfo.CallbackObject, data)
    end repeat
    end CheckAsyncStatus
    ----------------------------------------------------------------------

    The above code sets up a mechanism for registering callbacks with the subject "bar code monitor" and uses a timeout object to periodically check the State of the asynchronous actions.

    Now any object who wishes to be notified of an event fits simply by using the addEventListener method. Or let's say that we want our object of global struggle to listen to the returned data. The next Parent script would be created things.

    -control

    global gBarCodeMonitor

    the new me
    gBarCodeMonitor.addEventListener (I, #processData, #DataReady)
    return to me
    new end

    processData me, given
    -do something with the data
    end processData
    -------------------------------------------------------------------------

    You then create your objects in preparemovie.

    global gBarCodeMonitor
    global gControl

    on prepareMovie
    -installation Global Singletons

    If gBarCodeMonitor.voidP then
    gBarCodeMonitor = script ("Monitor Bar Code") .new)
    end if

    If gControl.voidP then
    gControl = script("Control").new)
    end if
    end prepareMovie
    ---------------------------------------------------------------------

    With this configuration, you can have several objects to register for an event and a unique object with several events.

    If you are not familiar with the scripts of Parent. So take the time to learn. The programming of your life will become much easier the day you're going to OOP.

    I have not test the code, so there may be a typo or something. But the basic idea is there.

  • New HP Photosmart 7520 e-all-in-one printer from the box, removed the tape and cartridge access

    I have a new HP Photosmart 7520 e-all-in-one printer just out the box. I removed the tape and cartridge access door does not open more than 40 degrees. The figure represents about 80 degrees. I'm afraid to force it. I can't put new cartridges in the printer. Very frustrated trying to get help. It doesn't seem to be a phone number or Web site for direct assistance. HP has really gone down hill. Help!

    Hello

    Mine is about 45 degrees, sufficient space to install the ink cartridges.

    Kind regards.

  • How to remove the alarms and events database of Citadel?

    Hello

    I use LV 2010 with DSC.

    I made a mistake in my program and I wrote too much data event and alarm at the Citadel. Database *.mdf/*.ldf files are quite large > 1 G. Normally, I connect only two alarms per day. I want to delete all events alarm + data before a certain time of stamps for example. 1.1.2011. How can I do? I tried to use MAX and perform the operation so I wrote small program which reach the data from temporary database and then remove it. Yet I can find old events and alarms... I am able to remove the traces of old but not the events/alarms. How do I remove the alarms and events?

    Thanks, Jim

    Hi Jim,.

    Have you seen this:

    http://forums.NI.com/T5/lookout/how-can-I-delete-alarm-and-event-data-from-a-Citadel5-database/m-p/5...

    Not sure if it is valid with the current version, but worth it.

  • My stored user names and passwords are removed several times each time the computer restarts. ______

    My "XP Home Edition' Service Pack 3 > stored user names and passwords are removed several times each time the computer restarts.

    Please check the LINK for the process that I'm going through, but nothing helped.

    http://www.box.NET/shared/zcokjesxx3

    Thank you for your kind cooperation.

    Sincerely,
    Frank

    Hi Ajay,

    It worked!

    Was the only thing that I changed, I added a % USERPROFILE % so he looked like that before

    %USERPROFILE%\Application data

    Instead of like this USERPROFILE%\Application Data

    Not sure if this was necessary to make - but again - it WORKED...

    Thank you very much for your time and your help is to solve this for me.

    Sincerely,

    Frank

  • DEFENDER lights. He tells me it's off and it must be enabled. I tried several times and I can't activate it. I see the icon in my field of security. The ICON in my programs (install/remove) is NOT there? ERROR message 0x80071A90__

    I would be grateful with the help of an EXPERT.  I would be very grateful if you can help me.

    DEFENDER lights.  He tells me it's off and it must be enabled.  I tried several times and I can't activate it.  I see the DEFENDER icon (it looks like gray Castle) in my field of security.  The ICON in my programs (install/remove) is NOT there?  0x80071A90 error message
    98CB24AD-52FB-DB5F-A-15-C8B3B9AIE18E

    In ADDITION, 2nd edition: I have an infected memory stick digital camera.  It has infected my computer 4 times from AUGUST 2009 I realized that it was the culprit.  It leads to the DEATH of SCREEN BULE.  He arrived Friday.  I made the recovery of the system.  I REINSTALLED it.  QUESTIONS: What should I do with this memory stick?  Throw it in the trash?  I lost 6 months of precious photos.  Can I move photos or keep the photos?  What do you recommend?

    In ADDITION, through the memory stick infect my computer and then the PICTURES who made the infection.  About 3 or 4 flash drives have been put in my computer.  Are they all infected?  I have College CRITICISM of work on one that I can't lose.  What should I do?  Should these flash drives be CLEANED of INFECTION?  They CLEAN themselves without losing me my files stored?  What do you recommend?  I need someone to assess whether or not they are infected?

    The infected memory stick infects my digital camera?  And my Photosmart HP ALL IN ONE printer?  Are they ALSO infected?  Will be going to infect my computer.

    I do not think that the SECURITY SOFTWARE I have: (free from Comcast) Norton and Microsoft Security Essentials, are fighting the infection from the memory stick.  It would be good to have an EXPERT evaluate the memory stick and tell me what they think.  As well as my flash drives, an expert must evaluate and tell me if 3 flash drives are infected? And they are clean? And the files that I have on them can be saved?

    I hope you can help me, THANK YOU, WG

    First, you have to run two anti-virus programs.  This is NOT recommended.

    Second... you state one of them is Microsoft Security Essentials.  If this is the case, you can't turn on Windows Defender because MSE already made defender and stops automatically Defender because it is no longer necessary.

    Difficulty of these 2 things and your problem should be solved.

  • I can't open my apps in creative cloud; whenever I get the trial version and the question to purchase. But I am a member for several years now. We have already removed all apps and installed them, but it does not work. What should do?

    ?  I can't open my apps in creative cloud; whenever I get trial versions and the question to purchase. But I am a member for several years now. We have already removed all apps and installed them, but it does not work. What should do?

    Troubleshooting FAQ: What should I do if I have a subscription, but my application acts as if I had a trial?

  • Copy and paste large event

    Hello everyone

    I'm working on a big VI and difficulties to run on different screen resolutions. Too many controls, indicators, charts, etc. If I let Labview resize objects and sizes of fonts all gets messy. Because of this, I decided to create several files of VI, one for each screen resolution. Then the first VI to run detects the actual resolution of the screen and load the right VI of this form.

    Everything works like a charm, but when I need to update something in my code (put a new sub - VI to run, create a new case of event within the structure of the event, etc.), I have to do the SAME procedure several times to update all the screws with different screen resolutions.

    After long reflection I came to the solution to remove all Boolean values or flags the while loop, set the buttons like "Switch releasing" and restore the previous state of the button programmatically. Given that I have never (or almost never) update something on the front, I can make all the necessary changes in a single resolution VI and after finishing all I can just copy the while loop and paste in all screen resolution files. After that I just have to connect a wire (for groups of references) and I'm good to go. All screen resolutions files work identically.

    The problem: when I copy while loop and paste it into a new VI, all the events of structures of event (to handle the case) are not preserved. Then, I need to change the events that will handle each case in the structure of the event and repeat the same procedure for all screen resolutions files. Since is impossible to Labview allow to adjust items and size of fonts and distribution, I have to continue to use multiple files.

    If I solve the problem with events that are not preserved when I copy and paste the while loop, everything will be fine.

    My code is really very important, with several SubVIs and all that, but the attached files will show you the main idea of the problem I have. Open resolution 1(vi), copy all looped and paste it in resolution 2.vi. The main idea was just to connect a wire and I'd be ready to go, but events are not kept in the structure of the event.

    Thank you

    Dan07


  • Make a mistake trying to remove several lines

    Hi Experts,

    Working in jdev 11.1.1.3.0 with ADF BC and rich faces.

    I am trying to delete several records in the table, everything works fine if I use the filter or not using not horizontal scroll bar of the table. If I try to remove the last recordings on the table and are removing the UI and DB also, but I get the error message like

    ADFv:Count find the line: _ $< to-calc >$ cur key:oracle.jbo.key [2333] inside the mother: XxwfsAvcardXXXXXXXVO1Iterator with key: null

    I changed my method with the link below

    Re: Array of line selection JDev 11 g-Multiple-error Ctrl + A

    but until I get the same error:

    Method:

    {} public void deleteRec (ActionEvent actionEvent)
    Add the code in the event here...
    RowKeySet rowKeySet = (RowKeySet) this.embossTB.getSelectedRowKeys ();
    CollectionModel cm = (CollectionModel) this.embossTB.getValue ();
    Line specRow = null;
    RowList ArrayList = new ArrayList();
    int listLength = 0;
    ArrayList < number > printReqLST = new ArrayList < number > ();
    Vo1 ViewObject = null;
    Boolean flag = false;
    for (object facesTreeRowKey: rowKeySet) {}
    cm.setRowKey (facesTreeRowKey);
    JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding) cm.getRowData ();
    specRow = rowData.getRow ();
    rowList.add (specRow);
    listLength ++;
    }
    for (int index = 0; index < listLength; index ++) {}
    specRow = (Row) rowList.get (index);
    Number of printReqID = (Number) specRow.getAttribute ("PrintRequestId");
    String PrintState = specRow.getAttribute("PrintState").toString ();
    If (PrintState.equalsIgnoreCase ("PRINTED")) {}
    System.out.println ("remove cann't');
    FacesContext fctx = FacesContext.getCurrentInstance ();
    FacesMessage message =
    new FacesMessage ("cann't delete selected line:"+ printReqID ");
    message.setSeverity (FacesMessage.SEVERITY_ERROR);
    fctx.addMessage (null, message);
    } else {}
    System.out.println ("Delete");
    flag = true;
    specRow.remove ();
    }
    }

    {if (flag)}
    System.out.println ("before");
    commitRows();
    }
    }

    Can someone help me...

    Hello

    In your af:table try to replace lines = ' #{bindings. " XxwfsAvcardEmbossInterfaceVO1.rangeSize}"and
    fetchSize = "#{bindings." XxwfsAvcardEmbossInterfaceVO1.rangeSize}' with
    lines = ' #{bindings. " XxwfsAvcardEmbossInterfaceVO1.estimatedRowCount}"and
    fetchSize = "#{bindings." XxwfsAvcardEmbossInterfaceVO1.estimatedRowCount}.

    Regds,
    Briant

    Published by: Aline Sep 9, 2010 10:52

  • How to remove several photos library icloud?

    I use icloud photos with multiple devices, including an iPhone 4, iPad, Macbook pro and two PC.

    My icloud library is too large, with many duplicates (same photo taken several times) and many photos, I don't want to keep.

    Deleting photos in the library using the icloud library is a slow and tedious process.  I can remove only one at a time, each time takes 20 seconds or more, even with Internet broadband.

    How can I select and delete several photos at once?

    Hello rhwolfson,

    Thank you for using communities Support from Apple!

    Looks like you want to be able to remove several photos icloud photo library at the same time.  I will do my best to help find a solution for you.

    To delete multiple photos, the easiest method is to sign in iCloud.com on one of the computers you listed.  Once logged in, click on the photos icon.  When you are in the view 'Moments', you should see "Select of Photos" at the top right of the browser window. Click on 'Select Photos'.  You should now be able to select multiple photos and then click on the "Remove" button that appears.  This should allow you to delete several photos at the same time.

    Have a great day!

  • I deauthorised all my computers several times and iTunes still shows that I have authorized 5.

    I allowed off all my computers several times and iTunes still shows that I have authorized 5. I can not re - allow one of my computers and cannot allow overall because I did last October. I tried a logout and back logging, remove the SC info folder etc... Any ideas?

    I allowed off all my computers several times and iTunes still shows that I have authorized 5

    Normally, you can only authorized computers off once a year.

  • Removal of damaged and unreadable files

    After recovering from a failure of the HD, restoration has added a few corrupted files. I can't remove them and have used all of the methods suggested, I could find (for example, chkdsk, disk cleaner, unlocker, safemode, Hiren BootCD)? Apparently the failed drive content/caused some files to become corrupt were then copied to the backup file and more later restored corrupted.

    I replaced the defective drive and then restored from a backup, Acronis. The Documents and Settings folder found \temp so I could copy the files needed for new Documents and Settings. Everything seemed to have worked fine until I tried to remove the Documents and Settings is no longer necessary to \temp. Now, I have a number of different files in \temp which cannot be deleted. Error when I try to remove one of the offending files is "cannot delete [filename]: the file or directory is corrupted and unreadable."

    Can someone suggest another method to clean up this mess short of reformatting the new drive and reinstall again? TIA.

    Hello

    ·         Do you have an error message when you run the disk check?

    I suggest to run the check disk in safe mode and check if it helps.

    WARNING: When Chkdsk detects problems with the file system and tries to repair the damage, data loss may occur. Microsoft does not recommend running Chkdsk with the /f command-line switch unless you have a full backup of your hard drive.

    Attempt to repair the damaged file, the folder or the index system using check diskfile. To do this, follow these steps:

    (a) click Startand then click run.

    (b) in the Open box, type chkdsk /f :, where is the letter of the drive on which the file is damaged, the folder or the file system index exists.

    (c) click Yes to schedule disk check when the computer is restarted.

    (d) restart the computer and let the disk check run and check.

    NOTE: If the hard disk is large, Chkdsk may take several minutes to several hours to complete.

    See also: http://technet.microsoft.com/en-us/library/bb457122.aspx

  • Add/Remove components error and DVD driver error: Windows cannot load the driver for this hardware device. The driver may be corrupted or missing. (Code 39)

    Original title: Add/Remove components error and DVD driver error

    Yesterday, I removed several components of windows to attempt to clean my cpu. After the reboot, I noticed that my DVD drive disappeared. I tried to update the driver but told me I have the most updated version, I uninstalled and reinstalled the drive, but I still get the same error. Under Driver Details, it shows that I have a lot of drivers for my Phillips DVD player. However, the status of the device is the following: Windows cannot load the driver for this hardware device. The driver may be corrupted or missing. (Code 39) Click Troubleshoot to start the troubleshooter for this device. I've done the troubleshooting, and the two options has not fixed the problem.

    Then I tried to add windows components that I removed, thinking maybe that was the problem. However, when I try to add them, I get an error message that says: 'Setup cannot copy the file zClientm.ex_' it shows the location of this file as being in windows/i386, and of course, the file is located in this folder. So when I go to browse to locate the file, I find and click on it to open it, but I keep getting the same error message that the file is not found and Setup cannot continue.

    I realize that this problem seems very rare and weird, but any help at all would be appreciated. Thank you.

    Hello
     
     
    Code 39: Windows cannot load the driver for this hardware device. The driver may be corrupted or missing. (Code 39)
    Explanation of error codes generated by the Device Manager in Windows XP Professional http://support.Microsoft.com/kb/310123
     
     
    Method 1.
    Microsoft Automated Troubleshooting Services scans your computer and detects that the root causes of common problems, then automatically solves the problems that he finds and offers additional resources if the problem is not resolved. Click run now in the article below.
    Your CD or DVD drive cannot read or write media
    http://support.Microsoft.com/GP/cd_dvd_drive_problems
     
     
    Method 2.
    Also, try the methods listed in the section below and check.
    Your CD or DVD drive is missing or is not recognized by Windows or other programs
    http://support.Microsoft.com/kb/982116
     
     
    I hope this helps.

    Thank you, and in what concerns:
    Shekhar S - Microsoft technical support.

    Visit our Microsoft answers feedback Forum and let us know what you think.
    If this post can help solve your problem, please click the 'Mark as answer' or 'Useful' at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • my account has been hacked several times and sends mail spam to the people on my list

    my account has been hacked several times and is to send spam to people on my list. I changed my password several times and it continues to happen. I took everyone off my email list with the exception of an e-mail address that I created to alertme in the case of this kind of thing happens, it works. I pay for this msn messaging service and I'm upset that anyone can hack my email so easily. I want that stopped.

    It is up to you to use Kaspersky Rescue Disk 10 to remove any malware. The hot spare is a bootable Linux distribution that will search for and remove malicious software that can hide when the HD is active.
    Booting from the rescue disk will ensure the HD is not Active -Kaspersky Rescue Disk 10

    Once the system is cleaned up, contact MSN and ask another reset of password.

    Expert MowGreen Windows IT Pro - consumer safety

  • Error message: problem loading parameters and check the event log or ask the administrator

    My wallpaper, the desktop icons and most of my documents are gone.

    I have Vista Home Premium and a couple of days and I connected my desktop background was changed. Several desktop icons are missing, and a message came up saying there was a problem loading my settings and check the event log, or ask the administrator (me) for more details. All my "Favorites" were missing in the sidebar and my documents and recorded images folders are empty. Microsoft customer service tells me there is an error in my code for the identification of product (from the Windows Activation in systems and Maintenance) so I can't help out.

    Any thoughts? Thank you!

    Hello, G25

    It is likely that your user profile is damaged. I would advise to create a new user account and test if you get any errors. If everything works as expected under the new user account, you can start to recover your account profile by following the steps on the following link: difficulty of a user profile is corrupted

    David
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

Maybe you are looking for