Repeat the small piece of code 1-100 hundred times with each code with a different instance name?

Hi, here is a part of my code:

player_mc.onEnterFrame = function() {}

If (enemy0.hitTest (this)) {}

enemy0. Speed = 0;

} else {}

enemy0. Speed = 1;

}

If (enemy1.hitTest (this)) { }

enemy1. Speed = 0;

} else {}

enemy1. Speed = 1;

}

};

Note the Red code, I need to repeat an unknown quantity still, but with the number on the end of the enemy incremented by 1 each time. It starts with 0 as you can see the code just above the red. I've heard for loops using 'i' but I'm not sure how to use. Please help and explain if possible. Thanks for reading and/or you answer.

Edit: ah, this forum is not to let me highlight red. This editor is also a failure. Well, when I say code red this code:

If (enemy1.hitTest (this)) {}

enemy1. Speed = 0;

} else {}

enemy1. Speed = 1;

}

You can use a for loop but you should have the number of enemies available somehow.   To be able to target the many enemies by using the same code in a loop, the notation vracket is used as a string value is interpreted as an object...

player_mc.onEnterFrame = function() {}

for (i = 0; i

If (_root ["enemy" + i] .hitTest (this)) {}

_root ["enemy" + i] .speed = 0;

} else {}

_root ["enemy" + i] .speed = 1;

}

}

}

This code assumes that the enemies are on the main timeline.  Will they live elsewhere then you need to adjust the targeting

Tags: Adobe Animate

Similar Questions

  • Why this small piece of code work

    A small piece of code, but get an error. What I'm missing here.

    Here is the error message:
    Invalid CFML construction found on line 27 in column 67.
    ColdFusion has been looking at the following:

    LTE

    The CFML compiler treated:

    * an expression starting with "#", on line 27, column 11. This message is usually caused by a problem in the structure of expressions.
    * The body at the beginning of on line 24, column 2 cfoutput tag.

    who did it, thanks

  • I repeated the small size of message in the folder C

    I repeated the small size of message in the folder C

    Hello

    · Were there any changes made on the computer before the show?

    I suggest you follow the steps below:

    Run the disk cleanup on the computer. You can check the link for the procedure: Description of the tool in Windows XP Disk Cleanup: http://support.microsoft.com/kb/310312

    Also check out the link and try the steps listed in the link: how to make a computer faster: 6 ways to speed up your PC: http://www.microsoft.com/atwork/maintenance/speed.aspx#2

  • Repeat/loop small amount of code.

    Hi how to make this code is constantly repeating, because it runs once. Im not very good with the listeners, I know functions and variable etc. If im not so bad. Help, please.

    Code:

    If (health < = 0) {}
    gotoAndStop ("mainDead");
    }

    Its on a framework, not a MC.

    AC 2

    Thank you.

    Try the following...

    this.onEnterFrame = function() {}
    If (health<=0)>

    delete onEnterFrame;

    gotoAndStop ("mainDead");
    }
    }

  • Script to replace the small caps that are typed in capital letters with capital letters (A = &gt; a, B = &gt; b, etc...)

    I am looking for a way to replace the small caps that are typed in capital letters by their normal equivalents.

    I have a text that contains many names that should all be set in small capitals.

    In fact, they are, but because the letters are used for the first letters that they don't fit.

    In short: I would like to be able to look for A, B, c... (in small capitals) and replace them with (a, b, c...) in small capitals only once.

    (compare two tables?-> is this possible in indesign scripting)

    Hi Cramik,

    Try this.

    var doc = app.activeDocument,
        _char = doc.stories.everyItem().characters.everyItem().getElements();
    
    for(var i=0;i<_char.length;i++)
    {
            if(_char[i].capitalization == Capitalization.SMALL_CAPS)
            {
                    _char[i].capitalization = Capitalization.CAP_TO_SMALL_CAP;
                }
        }
    

    Kind regards

    Cognet

  • Debug a small piece of code

    I'm working on a few scroll arrows that move a Clip up and down before they reached their maximum length. It works to move the clip to the top, but it does not stop at the maximum height, but retains the right to go. Here is the code from the image:

    topspan = - 560;
    bottomspan = 7.8;
    ValeurDeplacement = 10;



    Here is the code for the button:

    on {(overview)
    If (_root.predes._y > topspan) {}
    onEnterFrame = function () {}
    _root. PREDES._y = _root.predes._y - ValeurDeplacement;
    trace ("PREDES Y:" + _root.predes._y + "is superior to" + topspan);
    }
    } else {}
    onEnterFrame = null;
    }
    }

    (deployment, dragOut, releaseOutside) {}
    onEnterFrame = null;
    }


    The trace command shows me what is happening. _root. PREDES._y gets lower and lower, until finally she is less than topspan. At this point, it should make the statement "else" and onEnterFrame set to null. But it is not that. Instead, I get a trace statement that says "PREDES Y:-662.2 is greater than-560.

    Dragout/deployment/releaseoutside code works very well.

    Thank you, Craig. (The temptation to hit my forehead and scream "duh" is overwhelming).

  • where can I get the source code for the correction of a bug for a long time with tabs?

    When I right click on a bookmark or a link, so that I have to scroll down open the link in a new tab. I want to change the code to fix this bug, so I can open links in a new tab automatically by default. do this last properly as in netscape. all browsers since have faulty management of tabs.

    See:

  • STARTING in the same column several times with 2 different condition

    Hello world

    I have a small question, but I can't find the answer. Can someone help me with this one? Look at this example:
    WITH T AS (
      SELECT 'a' as Name, 1 as v FROM DUAL
      UNION ALL
      SELECT 'a' as Name, 2 as v FROM DUAL
      UNION ALL
      SELECT 'a' as Name, 2 as v FROM DUAL
        UNION ALL
      SELECT 'b' as Name, 1 as v FROM DUAL
        UNION ALL
      SELECT 'b' as Name, 1 as v FROM DUAL
        UNION ALL
      SELECT 'b' as Name, 2 as v FROM DUAL
    ) SELECT DISTINCT name, 
             COUNT(DECODE(v, 1, 1, null)) OVER (PARTITION BY name ORDER BY v) as v1,
             COUNT(DECODE(v, 2, 1, null)) OVER (PARTITION BY name ORDER BY v) as v2
        FROM T
      ORDER BY 1;
    This returns:
    NAME V1                     V2                     
    ---- ---------------------- ---------------------- 
    a    1                      0                      
    a    1                      2                      
    b    2                      0                      
    b    2                      1                      
    But what I need in a single row with the count of 1 and 2 by name. How can I get without using subqueries as (the following query returns the correct result)
    WITH T AS (
      SELECT 'a' as Name, 1 as v FROM DUAL
      UNION ALL
      SELECT 'a' as Name, 2 as v FROM DUAL
      UNION ALL
      SELECT 'a' as Name, 2 as v FROM DUAL
        UNION ALL
      SELECT 'b' as Name, 1 as v FROM DUAL
        UNION ALL
      SELECT 'b' as Name, 1 as v FROM DUAL
        UNION ALL
      SELECT 'b' as Name, 2 as v FROM DUAL
    ) SELECT DISTINCT t.name, 
             (SELECT COUNT(*) FROM T z WHERE z.name = t.name and z.v = 1),
             (SELECT COUNT(*) FROM T z WHERE z.name = t.name and z.v = 2)
        FROM T t
      ORDER BY 1;
    The table I'm working on that has millions of records with subqueries it takes forever to run. The one with the analytical function takes less than 3 seconds.


    Thanks for your help!

    If I understand correctly, you need a global tally, not an analytical account. Something like:

    SQL> WITH T AS (
      2    SELECT 'a' as Name, 1 as v FROM DUAL
      3    UNION ALL
      4    SELECT 'a' as Name, 2 as v FROM DUAL
      5    UNION ALL
      6    SELECT 'a' as Name, 2 as v FROM DUAL
      7      UNION ALL
      8    SELECT 'b' as Name, 1 as v FROM DUAL
      9      UNION ALL
     10    SELECT 'b' as Name, 1 as v FROM DUAL
     11      UNION ALL
     12    SELECT 'b' as Name, 2 as v FROM DUAL)
     13  SELECT name, COUNT(DECODE(v, 1, 1, null)) v1,
     14           COUNT(DECODE(v, 2, 1, null)) v2
     15  FROM T
     16  GROUP BY name
     17  ORDER BY 1;
    
    N         V1         V2
    - ---------- ----------
    a          1          2
    b          2          1
    

    John

  • How the heck can I get rid of the drop downs. I have try several times with no results

    GET RID OF DROP DOWNS (STORY) WHEN I TOUCH TO AN ADDRESS

    Do you mean on the address bar of Firefox, where appears the URL, or as a web page that needs to enter your address?

    For the Firefox address bar, the categories of data displayed in the menu drop-down are defined in the Options page, Privacy panel. See this article for more information:

    Awesome Bar - find your Firefox bookmarks, history and tabs in the address bar - go to the section "How can I control what shows the address bar results, me?

    For forms in web pages, if you want to disable auto form fill completely, you can do that also on the Options page, sign confidentiality. See this article for more information:

    Check if Firefox automatically fills in forms

    Who help me?

  • I can't upgrade to the latest version of Firefox, I tried several times and each time that it fails, please tell me how I can solve this problem?

    I can't download the last update, I am told that I must but evertime I try fails. I left it for more than 2 hours and he still had the message saying it has been updated, it certainly cannot take this time, please tell me how I can fix this problem that I love firefox and would not have to return to the dreaded "internet explore.

    Have you tried the full installer from loading? You can get one here:

  • Created a slide show time with a different speed than the speed for which it has been created in Windows MEdia Center

    HELP PLEASE! 1

    I create a slide show with music in Windows Media Center.

    I have change in SETTINGS, the display time of 3 seconds.

    I have burn the slide show with music on a DVD.

    The copy on DVD playing 7 second display speed.

    I want to play as I created it, to fit the music.

    HOW?

    Thank you

    Rhod

    Sydney Australia

    Use the creator of Windows DVD or Windows Movie Maker (new versions available here) to refine your settings.

  • E - M5 Mark II: why LR6 can't work with the full 4:3 raw image for photos taken with a different aspect ratio?

    When you import raw, Olympus E - M1 or E - M10 images taken in different proportions to the native 4:3 sensor MFT format, LR will display the chosen as culture overlay to the full image captured by the sensor. This is very useful because in post processing time one can still control the exact position of the frame and change if necessary:

    lr6-oly.jpg

    I was very surprised to see that for the new E - M5 Mark 2 is not supported.

    The LR6 raw file exactly matches the image that was chosen during the shooting. 4:3 picture information are full present in the raw of the ORF file, which can be easily seen for example using Olympus Viewer.

    Is there a particular reason why this useful feature has been overlooked for E - M5 Mark II?

    Thank you

    Karsten

    Karsten, the Adobe engineer has just announced that the file you provided is actually the brand I don't have Mark II... or at least that's what shows the model name field in the EXIF data (which is what using LR, and therefore why you can see the complete data of pre cropped out). So, two possibilities:

    1. you have downloaded an older file (little likely, given the date of capture).

    2. your device is a brand I have, not a Mark II.

    3. you had already hacked the file to make it look like a brand, I have so that you could treat it in Lightroom before the release of LR6.

    What do you think?

  • RE: Adding several pieces of code to head Adobe Muse tags

    I would like to install a custom Facebook public pixel code to place in the head tag of website and also Google analytic, is - this easy to do? I can just copy and paste the two pieces of code, one over the other? Y at - it traps? You can place several pieces of code in the head of meta tags data? Thank you

    In this case, I suggest you place the code in the metadata section if your master page.

    the codes will have an effect on all the pages on which the respective master has been applied.

    And Yes you can at any time place codes more than once in the metadata.

    Kind regards

    Ankush

  • a solution of the box? Or code change is required?

    At high level, we understand what consistency is everything, now we want to start putting our hands with a CEP and see if it a real advantage for our existing J2EE applications.
    Is however not clear to me yet, if it's out of the box solution or it involves our existing J2EE applications with the specific API refactoring.

    Thank you

    Hello

    OK, in most cases, yes you need to change your application but how much change depends on how you want to use the consistency. If you just want to use it as a basic cache to avoid repeating the database calls so you can make it work with enough little changes. If you want to use features more consistency, you obviously more changes. It also really depends on how your application was built in the first place. If it's a well designed application with a good separation of concerns - that is, it has a well built the data access layer, so it's simple to connect only a layer of consistency. If the access code you DB spreads all over your application, then it will be a little more difficult.

    The simplest cache would be something called cache when your application needs to read the DB side where it first checks the cache, if the data is there it is used instead of a DB call, if it is not there it is read from the DB and added to the cache. Alternatively, if your DB access code is completely free confined and easy to move you might look put this code inside the cache stores and using write through. Your application then justs reads data from or writes in a cache and consistency and then calls your cache store to do the required DB access.

    Other things you should be aware of (which apply to any caching solution) are if your application is the only one who did the updates of the DB. Keep the cache and DB synchronized if other applications can update the database is something that must also be addressed. There a lot of patterns.solutions to do this, yet according to the specific use cases.

    There are so many ways to do something with the consistency it is a little difficult to be very precise on what advice to give. It depends a lot on your application, how it was built and your specific use case. Do not be put off however, feel free to ask as many questions as you want, no matter how they sound newbie - what is forum.

    JK

  • Try to get the first sentence only - code does not

    It makes me crazy - code works on a single page, but not on another, and I can't understand why. The code I use to get out of the first sentence of a field is as follows:

    < cfset variables.firstsentence = Find (".", #get_spotlight.description #) >

    < cfoutput query = "get_spotlight" >
    < p > < #title # < br / >
    #Left (description, variables.firstsentence) # (< a href = "database_spotlight.cfm? link_id = #link_id #" > learn more < /a >) < /p > < / cfoutput >

    It works here: http://www.richland.lib.sc.us/research.cfm

    I try to use the same code on another similar page, and the same code does not work. It takes only the first 40 characters or more and I don't know why. I guess it's something to do with the surrounding code, but I don't see what. Can someone enlighten us on that before go me crazy?
    Here's the page I'm working on: http://www.richland.lib.sc.us/sample/linkstest6.cfm?subjecttype_id=16
    And here's all the code (in case something else is causing the problem)

    < cfquery name = "get_links()" datasource = "links_1", dbtype = "ODBC" >
    SELECT links.link_id, links.title, links.link, links.description, links.url_home, links.icon, links.url_tutorial, links.discus,
    Links.Subscription, subjecttype.subject_name, subject.link_id, subjecttype.subjecttype_id, subject.subjecttype_id
    Links, subjecttype, subject
    WHERE links.link_id = subject.link_id
    AND subjecttype.subjecttype_id = subject.subjecttype_id
    AND (subject.subjecttype_id = #url.subjecttype_id #)
    ORDER BY title
    < / cfquery >

    < cfset variables.firstsentence = Find (".", #get_links.description #, 0) >

    Output (with some HTML stranger deleted - sorry for the lengthy code - I'm sure there's probably a shorter, more elegant way to do..):

    < cfoutput query = "get_links()" >
    < cfif subscription IS "Yes" >
    < cfif IS 'Home' icon >
    < cfif url_home IS "" > <!-> the same in-house/remote url ".
    < p > < img src = "" #icon #4.gif "alt ="database icon"width ="20"height ="20"align ="absmiddle"/ >"
    < span class = "bold" > #TRIM (title) # </span > < cfif get_links.discus IS 'YES' >
    "" < img src = "... / pictures/discus_logo.gif" alt = "DISCUS" width = "61" height = "17" align = "absmiddle" / > < / cfif > < br / >
    #Left (description, variables.firstsentence) # < br / > < a href = "#link #" title = "#TRIM (title) #-inside the library" > inside the library < /a > |
    < a href = "" #link # "title =" #TRIM (title) #-home access "> home access < /a >"
    | < a href = "database_spotlight.cfm? link_id = #link_id #" > < img src = "moreinfo4.gif" alt = "More information" width = "20" height = "20" align = "absmiddle" / > < /a > "
    < cfif url_tutorial IS NOT "" > | "."
    "< a href ="... /... "/PDF/ #url_tutorial #" > < img src = "tutorial4.gif" alt = "Tutorial" width = "20" height = "20" align = "absmiddle" / > < /a > "
    < / cfif > < / p >

    < cfelse > <!--> two show internal URL / remote
    < p > < img src = "" #icon #4.gif "alt ="database icon"width ="20"height ="20"align ="absmiddle"/ >"
    < span class = "bold" > #TRIM (title) # </span > < cfif get_links.discus IS 'YES' >
    "" < img src = "... / pictures/discus_logo.gif" alt = "DISCUS" width = "61" height = "17" align = "absmiddle" / > < / cfif > < br / >
    #Left (description, variables.firstsentence) # < br / > < a href = "#link #" title = "#TRIM (title) #-inside the library" > inside the library < /a > |
    < a href = "" #url_home # "title =" #TRIM (title) #-home access "> home access < /a > |" < a href = "database_spotlight.cfm? link_id = #link_id #" > < img src = "moreinfo4.gif" alt = "More information" width = "20" height = "20" align = "absmiddle" / > < /a > "

    < cfif url_tutorial IS NOT "" > | "."
    "< a href ="... /... "/PDF/ #url_tutorial #" > < img src = "tutorial4.gif" alt = "Tutorial" width = "20" height = "20" align = "absmiddle" / > < /a > "
    < / cfif >
    < /p >
    < / cfif >
    < cfelseif icon is "inhouse" > <!--see the internal url-->
    < p > < img src = "" #icon #4.gif "alt ="icon of the database"align ="absmiddle"/ >"
    < span class = "bold" > #TRIM (title) # </span > < br / >
    #Left (description, variables.firstsentence) # < br / > < a href = "#link #" title = "#TRIM (title) #-inside the library" > inside the library < /a > | < a href = "database_spotlight.cfm? link_id = #link_id #" > < img src = "moreinfo4.gif" alt = "More information" width = "20" height = "20" align = "absmiddle" / > < /a > "

    < cfif url_tutorial IS NOT "" > | "."
    "< a href ="... /... "/PDF/ #url_tutorial #" > < img src = "tutorial4.gif" alt = "Tutorial" width = "20" height = "20" align = "absmiddle" / > < /a > "
    < / cfif > < / p >
    < / cfif >
    < / cfif >
    < / cfoutput >
    < p > < / p >
    < h3 > librarian - selection of Web Sites < / h3 >
    < cfoutput query = "get_links()" > <! - no subscription sites - >
    < cfif subscription IS 'No' >
    < p > < img src = "" #icon #4.gif "alt ="icon of the database"align ="absmiddle"/ >"
    < a href = "" #link # "title =" #TRIM (title) #"> #TRIM (title) # < /a > < br / >"
    #Left (description, variables.firstsentence) # < br / >
    < a href = "database_spotlight.cfm? link_id = #link_id #" > < img src = "moreinfo4.gif" alt = "More information" width = "20" height = "20" align = "absmiddle" / > < /a > < /p > "
    < / cfif >
    < / cfoutput >

    Thank you for reading this day and for any help or suggestion.

    YES! That's all--woohoo! Thank you very much. In addition, this explains why the same piece of code works on another page - this page I only shot one record instead of many. I looked up the ListFirst function and I understand that - but I never would have thought it myself.

    Thank you very much for coming up with the answer - and thanks to everyone who took the time to try it - I really appreciate it.

    Quote:
    Posted by: Swift
    Hi Michelle,

    If I'm right, then it is a simple problem. The simplest are good. :)

    That's what you have:


    <>

    #Left (description, variables.firstsentence) # (read more...)

    What you have done is in the position of the period off the first record in the data base by base and then applied to all records in the database. So you're cutting posted on 40 every time, because you will find that the first record in the database should be cut to the 40 position. Instead, you simply calculate the position each time inside the loop. In addition, we will just go ahead and make it even easier by using ListFirst...


    <>

    #ListFirst (description, ".") # (read more...)

    That should do it. By the way, if you really want the period appear (which I imagine you do), then just use:

    #ListFirst (description, ".") #.

    Instead of

    #ListFirst (description, ".") #.

    HTH,
    SWIFT

Maybe you are looking for