A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Code translation please

Hybrid View

  1. #1
    Patron Saint of Beatings WilloughbyJackson's Avatar
    Join Date
    Nov 2000
    Location
    Ro-cha-cha-cha, New York
    Posts
    1,988
    First comment: You do not have to delete the onMouseMove after each hit test, you can just have the hit tests listed in sequence.

    I.E.
    code:

    //...SNIP...
    this.onMouseMove = function(){
    if(_root.pin.hitTest(_root.r_balloon)){
    _root.r_balloon.gotoAndPlay("popped");
    }
    if(_root.pin.hitTest(_root.b_balloon)){
    _root.b_balloon.gotoAndPlay("popped");
    _root.b_balloon._visible = false;
    }
    if(_root.pin.hitTest(_root.g_balloon)){
    _root.g_balloon.gotoAndPlay("popped");
    }
    if(_root.pin.hitTest(_root.p_balloon)){
    _root.p_balloon.gotoAndPlay("popped");
    }
    }
    }
    //...SNIP...



    Or you could use an if else chain here.

    However, to make things easier, this is where you would use For loops and concatenation.

    First, rename your balloon movie clips to:
    balloon_0
    balloon_1
    balloon_2
    balloon_3

    Next you would set up a for loop and use concatenation to check each
    of the balloons.

    Concatenation is the operation of joining two character strings end to end or a string and variable.

    In otherwords if you have this:
    code:

    var i = 0

    _root["balloon_"+i]



    is exactly like saying this:
    code:

    _root.balloon_0



    You follow me so far?

    Okay..here's the example:
    code:

    //...SNIP...
    this.onMouseMove = function(){
    //FOR LOOP CODE IS LIKE THIS
    //for (starting number;repeat this until this condition is no longer true;how
    //the number will increase. ++ in Flash means it will increase by 1 for //each time through the loop.
    for (var i = 0;i <= 3;i++){
    if(_root.pin.hitTest(_root["balloon_"+i])){
    _root["balloon_"+i].gotoAndPlay("popped");
    }

    }
    }
    //...SNIP...


  2. #2
    Senior Member
    Join Date
    May 2006
    Posts
    119
    sorry to take so long to get back to this thread. Thank you for the mini tute on for loops, I have read up on them before, but this has been the easiest to understand. I will definately make a n effort to get to know it better.


    Thanks again

    Mark

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