# Is This Right

**URL:** <https://forum.kirupa.com/t/is-this-right/63890>\
**Category:** programming\
**Created:** [September 10, 2004, 11:03pm UTC](https://forum.kirupa.com/t/is-this-right/63890 "2004-09-10T23:03:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enix591](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/enix591/32/751_2.png) [@Enix591](https://forum.kirupa.com/u/Enix591)\
**Post date:** [September 10, 2004, 11:03pm UTC](https://forum.kirupa.com/t/is-this-right/63890/1 "2004-09-10T23:03:35Z")

</div>

Hey can somebody chek this code out, for some reason it has no syntax errrors but it does not make my character(Sonic) move.  
This Code is in the actions frame on my Properties Layer Below that layer is the layer with sonic on it.

right now im just worried about making him move.

> 

/////Moving left And Right/////  
if (Key.isDown(Key.RIGHT)) {  
if (\_root.Sonic.Xspeed\<30) {  
\_root.Sonic.Xspeed += 3;  
}  
\_root.Sonic.Right = true;  
} else if (Key.isDown(Key.LEFT)) {  
if (\_root.Sonic.Xspeed\<30) {  
\_root.Sonic.Xspeed -= 3;  
}  
\_root.Sonic.Right = false;  
} else {  
/////Friction/////  
if (\_root.Sonic.Rolling=false) {  
\_root.Sonic.Xspeed \*= 0.7;  
} else if (\_root.Sonic.Rolling == true) {  
\_root.Sonic.Xspeed \*= 0.9;  
}  
}  
/////Where To Be/////  
x=\_root.Sonic.\_x+\_root.Sonic.Xspeed  
y=\_root.Sonic.\_y+\_root.Sonic.Zspeed  
\_root.Sonic.\_x=x  
\_root.Sonic.\_y=y

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 11, 2004, 2:06am UTC](https://forum.kirupa.com/t/is-this-right/63890/2 "2004-09-11T02:06:39Z")

</div>

Is that all the code you have? If so, you should define ‘Xspeed’ first. And I don’t know what your fla looks like, but the way you build your code, you should have a 2nd frame that says ‘gotoAndPlay(1);’

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 11, 2004, 3:55am UTC](https://forum.kirupa.com/t/is-this-right/63890/3 "2004-09-11T03:55:39Z")

</div>

if in the actions layer, shouldn’t you have a \_root.onEnterFrame = function(){} with all that in it, thats what i do anyways

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 11, 2004, 4:13am UTC](https://forum.kirupa.com/t/is-this-right/63890/4 "2004-09-11T04:13:26Z")

</div>

Thanks Alot!

Dauntless you solved my problem all i need was a “gotoAndPlay(1)” on my next Frame.  
Dr. Warm , not sure what that would do but thanks any ways.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 11, 2004, 7:49am UTC](https://forum.kirupa.com/t/is-this-right/63890/5 "2004-09-11T07:49:24Z")

</div>

Dr warms way is actually better… If you write your code like this:

```auto
this.onEnterFrame = function(){
 /////Moving left And Right/////
 if (Key.isDown(Key.RIGHT)) {
 if (_root.Sonic.Xspeed<30) {
 _root.Sonic.Xspeed += 3;
 }
 _root.Sonic.Right = true;
 } else if (Key.isDown(Key.LEFT)) {
 if (_root.Sonic.Xspeed<30) {
 _root.Sonic.Xspeed -= 3;
 }
 _root.Sonic.Right = false;
 } else {
 /////Friction/////
 if (_root.Sonic.Rolling=false) {
 _root.Sonic.Xspeed *= 0.7;
 } else if (_root.Sonic.Rolling == true) {
 _root.Sonic.Xspeed *= 0.9;
 }
 }
 /////Where To Be/////
 x=_root.Sonic._x+_root.Sonic.Xspeed
 y=_root.Sonic._y+_root.Sonic.Zspeed
 _root.Sonic._x=x
 _root.Sonic._y=y
} 
stop();

```

There is no need for the second frame. All the actions are preformed in 1 frame.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 12, 2004, 2:48am UTC](https://forum.kirupa.com/t/is-this-right/63890/6 "2004-09-12T02:48:08Z")

</div>

Yeah the other way, in two frames was used in flash 5 and before, not that there’s anything wrong with that. I’m guessing you just hold an old tutorial or something.
