A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: using AS to rotate a mc?

Hybrid View

  1. #1

    using AS to rotate a mc?

    hi there, i have a movie clip of a cd, and i want it to start spinning as if it were playing in a cd player?

    how would i go about making it start off spinning slow then getting faster and then continue at a steady rate?

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    i=0;
    _root.mc.onEnterFrame=function(){
    i++;
    this._rotation =i;
    }
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Here's a version that has a controllable acceleration.

    code:

    // set this to maximum desired rate
    _root.mc.maxRate = 20;
    // set this to control the initial acceleration
    _root.mc.accel = 0.5;
    _root.mc.curRate = 0;

    _root.mc.onEnterFrame=function()
    {
    if (this.curRate < this.maxRate)
    {
    this.curRate += this.accel;
    }
    this._rotation += this.curRate;
    }


  4. #4
    Senior Member hum's Avatar
    Join Date
    Sep 2003
    Location
    CloudCuckooland
    Posts
    1,714
    Hi....
    This will speed it up gradually......(this._rotation + = i;)
    code:
    i = 0;
    _root.mc.onEnterFrame = function() {
    i++;
    this._rotation + = i;
    };


  5. #5
    Senior Member
    Join Date
    Sep 2004
    Location
    West Mids, UK
    Posts
    101
    all the above will work but jbum's one will work the best, why? simple the other two will keep increasing i to infinity, meaning that the illusion of the cd spinning up will also have the same illusion as it spinning down (when it gets past a certain speed) and also the illusion of it spinning backwards as well will happen.

  6. #6
    yeah i used jbum's.

    now, im wondering, if i have it spinning like it is, how can i get it to decrease to a stop as if someone pressed the stop button back to the original position?

    thanks
    Last edited by notaloserflash; 09-27-2004 at 10:42 PM.

  7. #7
    Senior Member
    Join Date
    Sep 2004
    Location
    West Mids, UK
    Posts
    101
    Well the answer is infront of your face really, just need to understand how the if loop works, but here is the answer for you based on jbums code...

    code:

    // set this to maximum desired rate
    _root.mc.maxRate = 0;
    // set this to control the initial acceleration
    _root.mc.accel = 0.5;
    _root.mc.curRate = 20;

    _root.mc.onEnterFrame=function()
    {
    if (this.curRate > this.maxRate)
    {
    this.curRate -= this.accel;
    }
    this._rotation -= this.curRate;
    }



    how does it work? simple, if the value of this.curRate is greater than the value of this.maxRate it tells curRate to decrease by the acceleration rate (this.curRate -= this.accel
    it then tells the object to rotate by that amount
    (this._rotation -= this.curRate

    hope that answers your question and better understands the flash code as well
    Originally posted by notaloserflash
    yeah i used jbum's.

    now, im wondering, if i have it spinning like it is, how can i get it to decrease to a stop as if someone pressed the stop button?

  8. #8
    yeah that works, but theres a couple problems

    first, it spins the opposite direction when slowing down, and second, it doesnt stop in the original position..

    is it possible to get it to stop in the original position?

    thanks

  9. #9
    actually dont worry about the spinning the wrong way, i just changed this._rotation -= this.curRate; to this._rotation += this.curRate;


    but about the stopping in the original position? is that possible?

  10. #10
    Senior Member
    Join Date
    Sep 2004
    Location
    West Mids, UK
    Posts
    101
    Well the code I gave you with your little change should have worked!... ack actually no it wouldnt have cause you are not reversing the cd rotation..

    basicly to correct the problem you would have to do somet like this...

    have the rotation speed go to a point where it rotates the cd so that it is at 180 degrees once it gets to its top speed, then decrease it at the same rate. That way it will stop at the same point it started at. Chances are there is an easier way than working out the algebra formula, jbum can you leand any insight??

    I think the algebra equation would be (bear in mind I aint touched algebra for like 8 years... gosh thats a long time since the good old days :'( )
    rotation = degree + (degree /2)

    actually i know that is wrong just cant be arsed to delete it lol

    rotation += degree, ...

    oh well I am tired tis 5 in the morning, i hate night shifts :'(

    Originally posted by notaloserflash
    actually dont worry about the spinning the wrong way, i just changed this._rotation -= this.curRate; to this._rotation += this.curRate;


    but about the stopping in the original position? is that possible?

  11. #11
    is there a way to just take it at the speed it goes at when its slowing down, then stay at a slow speed until it reaches the original position and stops there? like, a stop on original mc or something?

  12. #12
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    notalower - your correction makes sense. You want to keep spinning in the same direction, but the rate of change in the spin comes down.

    Now to answer your last question, how to stop at a particular spot...

    Lemme noodle on this one...

    [edit]

    Mebbe something like this? This won't look all that natural, but it does what you described.

    I'm assuming the stopping position is _rotation == 0.

    code:

    // set this to slowest (final) speed
    _root.mc.minRate = 1;
    // set this to control the initial acceleration
    _root.mc.deccel = 0.5;
    _root.mc.curRate = 20;

    _root.mc.onEnterFrame=function()
    {
    // slow down until we hit a speed of 1
    if (this.curRate > this.minRate)
    {
    this.curRate -= this.deccel;
    }
    this._rotation += this.curRate;
    // are we there yet?
    if (Math.round(this._rotation) == 0)
    {
    // yep, we're there.
    this._rotation = 0;
    delete this.onEnterFrame;
    }
    }

    Last edited by jbum; 09-28-2004 at 12:56 AM.

  13. #13
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    That reminds me, on an unrelated discussion, a few days ago, (somebody asked me how to do moire patterns), I came across a technique that replicates the 'shiny' pattern on a CD, somewhat:

    http://www.krazydad.com/bestiary/moire2.html

    This is produced by the interference pattern between two sets of concentric rings.

  14. #14
    Senior Member
    Join Date
    Sep 2004
    Location
    West Mids, UK
    Posts
    101
    Very nice moire pattern, could be adapted to a cd pattern as well so would be very nice. But i still think a simple fade would work better

    Originally posted by jbum
    That reminds me, on an unrelated discussion, a few days ago, (somebody asked me how to do moire patterns), I came across a technique that replicates the 'shiny' pattern on a CD, somewhat:

    http://www.krazydad.com/bestiary/moire2.html

    This is produced by the interference pattern between two sets of concentric rings.

  15. #15
    jbum - that is a pretty cool pattern, but its the top face of the cd and it has a label

    i actually used a high def scanner and scanned the cd, but anyway

    im changing the final speed of the script you gave me to stop it at a speed and continue at that speed until it reaches rotation 0, but only some values it will stop on rotation 0, i have only found that 1 works all the time, but i want it faster than that, otherwise it keeps spinning forever... i might be missing something, but i cant figure it out.. any ideas?
    Last edited by notaloserflash; 09-28-2004 at 03:53 PM.

  16. #16
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Depending on the values you choose, it may be skipping over 0 without _rotation ever being exactly equal to 0. You can deal with by changing this line:

    if (Math.round(this._rotation) == 0)

    to this:

    if (Math.floor(Math.abs(this._rotation)) < 1)

    Which stops it from spinning if the rotation is near zero. If the 'slow' speed is too high, then you may need to change the '1' to a higher number to get it to stop.

    - Jim

  17. #17
    ehr that gets it to stop in the right place, but it doesnt do the slowing down

    instead of slowly decreasing to speed x then going to the rotation < 1 at speed x, it is just spinning until it hits < 1 without the decrease in speed.

    it just does a full rotation until it is at a rotation < 1
    Last edited by notaloserflash; 09-28-2004 at 05:00 PM.

  18. #18
    do i need to do something like

    if speed traveling at is "x" then ask the question

    if (Math.round(this._rotation) < 1 )

    ?

    instead of just telling it to decrease the speed and ask for when it is < 1 at the same time?


    just trying to think of possibilities,

    thanks,

    nota









    edit** lol i have been trying this, and i did this


    if (this.curRate == this.minRate) {

    if (Math.round(this._rotation) < 1 )
    {
    // yep, we're there.
    this._rotation = 0;
    delete this.onEnterFrame;
    gotoAndPlay(31);

    }
    }

    and it slows down then stops upside down?
    Last edited by notaloserflash; 09-28-2004 at 05:13 PM.

  19. #19
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Yes, you're right. You can change it to something like:

    if (this.curRate <= kMinimumSpeed and Math.round(this._rotation) < 1 )


    In which kMinimumSpeed is the slow speed you want ....

    - Jim

  20. #20
    wow thanks a toooooooooooooooon guys!! finally got it working alright!

    nota

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