moving a box!

  • hamid_r_h
  • Born
  • Born
  • hamid_r_h
  • Posts: 2

Post 3+ Months Ago

I 'm trying to learn Flash and actionscript


now I want when the user press and release the left arrow a box(Move Clip) moves to left and countinue to move left when the user press right arrow the box moves to right and countinue to move right and same thing for up and down.
I wrote a script for it.
but I dont think it is the best way.
does any one know a better way?



here's my script:
Code: [ Select ]
onClipEvent (enterFrame) {
    this._x += s;
    if (Key.isDown(Key.Left)) {
        s1 = 0;
        s = -10;
    }
    if (Key.isDown(Key.Right)) {
        s1 = 0;
        s = +10;
    }
}
onClipEvent (enterFrame) {
    this._y += s1;
    if (Key.isDown(Key.Up)) {
        s = 0;
        s1 = -10;
    }
    if (Key.isDown(Key.Down)) {
        s = 0;
        s1 = +10;
    }
}
  1. onClipEvent (enterFrame) {
  2.     this._x += s;
  3.     if (Key.isDown(Key.Left)) {
  4.         s1 = 0;
  5.         s = -10;
  6.     }
  7.     if (Key.isDown(Key.Right)) {
  8.         s1 = 0;
  9.         s = +10;
  10.     }
  11. }
  12. onClipEvent (enterFrame) {
  13.     this._y += s1;
  14.     if (Key.isDown(Key.Up)) {
  15.         s = 0;
  16.         s1 = -10;
  17.     }
  18.     if (Key.isDown(Key.Down)) {
  19.         s = 0;
  20.         s1 = +10;
  21.     }
  22. }
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

Is this like what you're trying to do?

http://www.kirupa.com/developer/actionscript/xymove.htm
http://www.kirupa.com/developer/mx/movement_keys.htm
  • solaris
  • Student
  • Student
  • User avatar
  • Posts: 83
  • Loc: NC

Post 3+ Months Ago

wonder why ur script is so spaced out :shock:

im stupid hehe 8)
  • UNFLUX
  • Genius
  • Genius
  • User avatar
  • Posts: 6376
  • Loc: twitter.com/unflux

Post 3+ Months Ago

i fixed it for him :)
  • solaris
  • Student
  • Student
  • User avatar
  • Posts: 83
  • Loc: NC

Post 3+ Months Ago

looks alot better ;)
  • SycomCOmp
  • Graduate
  • Graduate
  • User avatar
  • Posts: 171
  • Loc: USA

Post 3+ Months Ago

I dont know if this was a neccessary post but I just had to say something after viewing your web site...

http://www.solarisdesigns.net/v4/site.html

Very nice but I cant get over how similar it looks like this

http://www.unflux.com
sorry if this was completely off topic I can never keep my mouth shut :P

Do you guys work together? :wink:
ok ok i'm done

later
:arrow: SycomCOmp :idea:
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

UNFLUX does not take kindly to rippers.

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 16 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.