A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Simple Question

  1. #1
    Junior Member
    Join Date
    May 2001
    Posts
    21
    This is a very simple question. I have one movie clip with instance name 'Dude' and I have one button. When I press the button, I want 'Dude' to move it's _x position 25 pixels to the right. But I want the viewers to see it move at a constant speed. I don't want it to just pop up towards the right. I want it to move there. What's the code to do this? Will I need a extra blank movie clip to do this?

    BB

  2. #2
    Member
    Join Date
    Mar 2001
    Posts
    36
    you could have a loop that moves it 1 pixel at a time, till it reaches 25

    code:

    ___________________________________


    function moveMC(this)
    {

    distance = 25;

    for (i = 0; i <= distance; i++)
    {

    this._x += 1;

    }

    }

    then on your button you can have

    on (release)
    {

    _root.moveMC(dude);

    }

    ___________________________________

    I'm not quite sure if flash will execute the loop and then place the mc 25 pixels to the right....or if it will move 1 pixel while the loop is being executed....let me know if this doesn't work

    hope that helps

  3. #3
    Senior Member
    Join Date
    Aug 2000
    Posts
    588
    graphicguru,

    Actually, a "for" loop will execute pretty much instantaneously, so this script will cause the MC to move immediately to 25 pixels to the right.

    You could try something like this on your dude movie clip:

    onClipEvent(enterFrame) {
    if(this._x < dudeMove) {
    this._x = this._x + 1
    }
    onClipEvent(load) {
    dudeMove = this._x
    }

    And then on your button:

    on(release) {
    Dude.dudeMove=Dude.dudeMove + 25
    }


  4. #4
    Member
    Join Date
    Mar 2001
    Posts
    36
    philter

    I totally realized it after I submitted!!


    I totally for got that a loop doesn't update or refresh until after the loop has completed.

    nice post... you hit it on the head

  5. #5
    Senior Member
    Join Date
    Aug 2000
    Posts
    588
    Thanks dude.

  6. #6
    Junior Member
    Join Date
    May 2001
    Posts
    21
    Thanks guys, I will give it a try.

    BB

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