A Flash Developer Resource Site

Results 1 to 18 of 18

Thread: for loop

  1. #1
    Senior Member
    Join Date
    Apr 2002
    Posts
    106
    how can i use a for loop to simulate a scale tween ?
    when i tried this :::

    on(rollOver) {
    for (var i = 1; i = 10; i++) {
    _root.homeButton._xscale += 5;
    _root.homeButton._yscale += 5;
    }
    }
    on(rollOut) {
    for ( i = 1; i = 10; i++) {
    _root.homeButton._xscale -= 5;
    _root.homeButton._yscale -= 5;
    }
    }

    it seems to go from only one position to another where u dont actually see the loop movement in between ?
    i tried different variations of variable incrrease but still the same thing happened ??
    any ideas ??
    cheers !!!!

  2. #2
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    A loop make all its calculations while being on just one frame. So a loop cant animate anything. And while the loop is running all other activities i Flash stands still.

    You can do a twoframe loop though.
    Have a If statement instead of the loop on the first frame (If(i==10) and so on) and on the second frame have the i=i+1 then go back to the first frame again.


  3. #3
    Senior Member
    Join Date
    Apr 2002
    Posts
    106
    great !! that will do it , but dont i have to initally set that value of i to 0 ? and where do i do that ?? if i do that in the first frame then wont it keep setting back to zero after each pass ???
    thanks again pellepiano

  4. #4
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    You can make an extra frame in the beginning to set the variable i=1 or set it in your preloader . (if you dont set it it will be 0 by default I think).

  5. #5
    Senior Member
    Join Date
    Apr 2002
    Posts
    106
    ok , in the first frame of the MC (with no instance of anything just that action ) i have set the variables ,
    i = 1 and j = 1 . . .
    then on the MC i have put this :::
    on(rollOver) {
    if (i != 6) {
    _root.homeButton._xscale += 15;
    _root.homeButton._yscale += 15;
    }
    }
    on(rollOut) {
    if (j != 6) {
    _root.homeButton._xscale -= 15;
    _root.homeButton._yscale -= 15;

    }
    }
    then on the 3rd frame i have put :::
    i++;
    j++;
    _root.homeButton.gotoAndPlay("homeLoop"); /*where homeButton is the instance of the clip with everything in it*/

    but alas it still doesnt work
    thanx again pellepiano



  6. #6
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Initially I thought you had buttons with the code in it because MCs cant have RollOver actions (if it is refferring to a function it might work) though).

    So my suggestion was to put the code in 3 frames instead where a button would tell the timeline to play.

  7. #7
    Senior Member
    Join Date
    Apr 2002
    Posts
    106
    yeah when i said MC that was true and the actions from my last post where atached to a button in the mC :::

    "So my suggestion was to put the code in 3 frames instead where a button would tell the timeline to play."

    now im getting confused ???

    if i dont put the code on a button how would it know when it is rolled over or not ???

    thanks AGAIN !!!

  8. #8
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Im getting confused too. So let me summarize ( i hope)

    •On main timeline theres a MC called homeButton

    Then you have a MC with three frames ( first frame with i=1 ( and a Stop action )

    Second frame your scaling script .
    Third frame with i=i+1 and back to play frame 2

    In this MC is also a button that when RollOver start to play the timeline.

    Then you might consider having an Else statement to tell whats happening after the scaling is done.

  9. #9
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Would something like this help? (attached as a clipevent to the movie you want to scale)

    Code:
    onClipEvent(load) {
      i = 1;
      j = 1;
    } 
    onClipEvent(enterFrame) {
      if (this.hitTest(_root._xmouse,_root._ymouse)) {
        if (i < 6) {
          this._xscale += 15;
          this._yscale += 15;
          i++;
        }
      } else {
        if (j < 6) {
          this._xscale -= 15; 
          this._yscale -= 15; 
          j++;
        }
      }
    }

  10. #10
    Senior Member
    Join Date
    Apr 2002
    Posts
    106
    oooh nearly ,,,, thats the closet so far except as soon as the clip loads in it goes really small and then on rollover it goes back again but thats it no further movement happens with any mouse move . . . .

    but to recap (clearly i hope ) ....

    *On main timeline theres a MC called homeButton
    *Then you have a MC with three frames -first defining i and j , (and nothing else) , second frame i have the button with this attached ::
    on(rollOver) {
    if (i != 6) {
    _root.homeButton._xscale += 15;
    _root.homeButton._yscale += 15;
    }
    }
    on(rollOut) {
    if (j != 6) {
    _root.homeButton._xscale -= 15;
    _root.homeButton._yscale -= 15;

    }
    }


    third frame i have :::
    i++;
    j++;
    _root.homeButton.gotoAndPlay("homeLoop");

    ?????
    thanks for your patience and time guys .

  11. #11
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Okay,

    I'll try to build something tonight, i'll let you know how I get on

  12. #12
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    I dont know. Im not that familiar with putting code on Mc's.
    So I usually do it the way I did it in F4 ( I skipped F5, but am now on MX), where I got used to using movieclips as controllers.

    But your code seems fine to me.

  13. #13
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Have a look on http://www.angelfire.com/electronic2/catbert/scale.html is that the kind of effect you're looking for? If so there is a link to the fla file on the page, if not i'll have another go

  14. #14
    Senior Member
    Join Date
    Apr 2002
    Posts
    106
    this is where i got the idead from ::
    http://www.clubmilk.com/milk.htm
    i tried to make it without code , ie just buttons and a MC but if the user scrolled over the button fast enough it could get stuck on the up (large ) part ...
    i will check out that file and let u know !!
    cheers !!!!

  15. #15
    Senior Member
    Join Date
    Aug 2000
    Location
    atlanta
    Posts
    1,008
    if i read this question correctly there is a very elegant and much more simple solution on the tutorials on turtleshell.com.

  16. #16
    Senior Member
    Join Date
    Apr 2002
    Posts
    106
    thanks for the cryptic reply monster , but the only place that link led my pc was to that infamous blue screen of death ....
    i have seem to have got it working using the example from that file ,its not as smooth as hoped but maybe with some tweaking ...
    thanks all for all !!!
    cheers !!

  17. #17
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    An edited file is available on the same url I posted before, it's more like the example from clubmilk.com now

  18. #18
    Senior Member
    Join Date
    Apr 2002
    Posts
    106
    yup cheers catbert , a tiny tweak and that works a treat !! thanx for your efforts !!
    owk

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