A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Fast and easy question

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    5

    Fast and easy question

    AS 2,
    trying to put this into a loop:

    Actionscript Code:
    ship1 = {}
    ship1.health = 0
    ship2 = {}
    ship2.health = 0
    ship3 = {}
    ship3.health = 0

    i tried

    Actionscript Code:
    for(var i; i <=5;i++){
        this["ball"+i] = {};
        this["ball"+i].alive = 0;
        }
    (Highlight isnt working T_T)
    but using this["ball" + i] when trying to create an object made my computer freeze when i started the script, iv tried a few adjustments and i still cant figue it out T_T

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    It's a ship or a ball? your first example is with ship1, ship2, the second with ball1, ball2. Appart from i that your loop is correct.

    gparis

  3. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    5
    i did mess that up cuz i posted it all in like 2 secs before i went somewhere, and i was using a ball program to test, and im sorry to say, but this code doesnt work, it freezes my computer when i run it, if the Super moderator doesnt know the answer then im gonna assume its impossible! xP

    Actionscript Code:
    for(var i; i <=5;i++){
            this["ship"+i] = {};
            this["ship"+i].alive = false;
            }

    the program works fine if i manually put in the 2 lines for each ship, but once again, ill say when i use this["ship"+i] it simply doesnt come out right
    Last edited by Slay; 01-27-2011 at 03:19 AM. Reason: meh..

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Give i a start value: for (var i = 1;....

    gparis

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center