Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-16-2012, 10:39 PM   #1
riztagar
Registered User
 
Join Date: May 2012
Posts: 3
Exclamation help in _x and _y direction!

I need lil bit help in actionscript 2.0
I've created a MovieClip moves to x direction but when it touch -X limit, it won't go for +X??

My Actions for MC:

speed = 9;

mc.onEnterFrame = function(){

this._x -= speed;
if(this._x < 34){
this._x += speed;
}
}


and my mc +X limit is 385
Attached Files
File Type: zip X Direction.zip (5.2 KB, 13 views)
riztagar is offline   Reply With Quote
Old 05-16-2012, 11:43 PM   #2
Prid
Prid - Outing
 
Prid's Avatar
 
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,191
Send a message via MSN to Prid Send a message via Skype™ to Prid
Default

You see, when it IS smaller than 34, it will start adding the value of speed to your X position, but at the same time, it will still subtract it as well. Once it adds to your X position until it is higher than 34, then it will stop adding the value of speed to your X position, so basically, you have a weak structure:

ActionScript Code:
checkVar = false; // declare this variable somewhere else, NOT inside enterFrame loop if(this._x < 34){     checkVar = true; } else if(this._x >= 385){     checkVar = false; } if(checkVar == true){     this._x += speed; } else {     this._x -= speed; }
__________________
I have returned, and am now 18
Prid is offline   Reply With Quote
Old 05-17-2012, 11:44 AM   #3
riztagar
Registered User
 
Join Date: May 2012
Posts: 3
Default Now its working :D

My final code is:

checkVar = false;
speed = 9;
mc.onEnterFrame = function(){
if(this._x < 34){
checkVar = true;
} else if(this._x >= 385){
checkVar = false;
}

if(checkVar == true){
this._x += speed;
} else {
this._x -= speed;
}
}

Now I want to add Pause function on it. When I Rollover my mc then it get pause.

Last edited by riztagar; 05-17-2012 at 11:50 AM. Reason: additional Info
riztagar is offline   Reply With Quote
Old 05-17-2012, 12:34 PM   #4
Prid
Prid - Outing
 
Prid's Avatar
 
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,191
Send a message via MSN to Prid Send a message via Skype™ to Prid
Default

make another variable:

pauseVar = false;

and change last code to this:

ActionScript Code:
if(pauseVar == false){     if(checkVar == true){         this._x += speed;     } else {         this._x -= speed;     } }

and then just turn pauseVar to TRUE when you want to, and it'll stop
__________________
I have returned, and am now 18
Prid is offline   Reply With Quote
Old 05-17-2012, 08:46 PM   #5
riztagar
Registered User
 
Join Date: May 2012
Posts: 3
Default

Quote:
Originally Posted by Prid View Post
make another variable:

pauseVar = false;

and change last code to this:

ActionScript Code:
if(pauseVar == false){     if(checkVar == true){         this._x += speed;     } else {         this._x -= speed;     } }

and then just turn pauseVar to TRUE when you want to, and it'll stop
Thanx a lot
riztagar is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:44 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.