A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Coping with code?

  1. #1
    Junior Member
    Join Date
    Dec 2002

    Coping with code?


    I was attempting to create a small animation where meteors are created at a random x position and go down the screen but Flash can't seem to handle the code i used. Is this incredibly intensive code? I didn't think so.

    PHP Code:
    onClipEvent(load) {
    init = {_x:Math.random()*550};
    i=0;i<549;i++) {
    i=0;i<399;i++) {
    _root["rock"+i]._y i;

    Am i doing something wrong?


  2. #2
    Senior Member mbenney's Avatar
    Join Date
    Mar 2001
    maybe thats not the best way to do it! for loops are notoriously cpu intensive, can you explain a little more what you are looking for? space shooter type asteriod field? you want the asteriods to scroll?

  3. #3

    It is intense for Flash

    You are telling flash to create 549 meteors all at once! That alone is intense for flash (but doable). Actually the thing you did wrong was with your nested for loop. You are using i in both loops which has given you an infinite loop.
    I am confused by what you are trying to accomplish with the infinite loop though. Basically from what I can see you are creating a meteor then trying to update the Y position of the first 399 meteors. You will never see these updates take place so in the end the nesting serves no purpose. Also, you aren't updating the value of init so the depth of each new meteor will overwrite that of the last. If it were me coding this I would take a slightly different approach:

    This will be more incremental (fewer meteors at a time) and easier to understand ( less cryptic, more organized code):
    PHP Code:
    onClipEventload ){
    //What is the minimum and maximum depth of the meteors?
    minMeteor 100;
    maxMeteor 1000;
    curMeteor minMeteor;

    //Variables that must be initialized for main program loop.
    looper 0;
    interval 20;

      This function will create a specified amount of meteors
      and randomly set the x position of each meteor.
    function createMeteorsnum ){
    initX Math.random()*550;
    _parent["rock"+curMeteor]._x initX;
    _parent["rock"+curMeteor]._y 0;
    //This ensures we do not start overwriting other movies.
          //which is important in games where you are creating many
    if( curMeteor maxMeteor)
    curMeteor minMeteor;

    onClipEvententerFrame ){
    //Basically everytime we enter this frame this code is run.
      //If looper mod interval is 0 then we will create meteors.
      //since interval = 20 we will create 5 meteors every 20 frames.
    if( looper interval == 0)

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