Question : AS3: moving object to and from specific location

i am trying to move the object to specific location, the scenario is like this:
when click move to 400 on x coordinate
when click again go back to its original location

please see the code
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
// first try
help_mc.addEventListener(MouseEvent.CLICK, moveToLeft);
function moveToLeft(e:MouseEvent):void {
	if (allObjectOfTitle.x == 400) {
		new Tween(mp3_mc, "x", Regular.easeInOut, 326.3, 1066.3, 1, true);
	}
}
 
help_mc.addEventListener(MouseEvent.CLICK, moveToRight);
function moveToRight(e:MouseEvent):void {
	if (allObjectOfTitle.x == 1140) {
		new Tween(mp3_mc, "x", Regular.easeInOut, 1066.3, 326.3, 1, true);
	}
}
 
//-----------------------------------------------------------------------------
help_mc.addEventListener(MouseEvent.CLICK, moveToLeft);
function moveToLeft(e:MouseEvent):void {
	if (allObjectOfTitle.x == 400) {
		new Tween(mp3_mc, "x", Regular.easeInOut, 326.3, 1066.3, 1, true);
	} else if (allObjectOfTitle.x == 1140) {
		new Tween(mp3_mc, "x", Regular.easeInOut, 1066.3, 326.3, 1, true);
	}
}
Open in New Window Select All

Answer : AS3: moving object to and from specific location

ok as i said before, use a trace action to check your conditions.

if i implement your conditions for the if statements.

the third time i click if you check the coordinates that you're trying to compare with, the Tween class has dumped your items on 400.25 and not 400.3 - i guess it's not pixel accurate. Therefore neither of your conditions are true and thus nothing will happen.

you're better off specifying a range.

i.e. if allObjectOfTitle < 500

and if allObjectOfTitle > 1000 or something along those lines.
Random Solutions  
 
programming4us programming4us