Copy link to clipboard
Copied
Hi,
I'd like to create a mini game in my game. The aim of the mini game would be :
To push a cow in a truck by clicking quickly with the mouse. If you're not fast enough, the cow is returning to its original point.
So, I think I must create the cow movieclip and indicate coordinate x something and y something.
Then tell the code that everytime the player click, the movieclip goes y +1.
BUT, every 0.5 seconds the movielcip goes y-2 (unless it's at his original coordinates).
And tells the code that, when the cow movieclip is at x.somethingelse and y.somethingelse, the puzzle is complete.
Now..last but not least... How I can I do that ?
Would it be something like this ? :
cow = new cowMovieclip;
addchild(cow);
cow.x = 0;
cow.y = 0;
cow.addEventListener(MouseEvent.CLICK, push, false, 0, true);
public function push(e:MouseEvent):void{
// I don't think it's like that
cow.x = +1;
cow.y = +1;
}
if (cow.y = 30){
allPuzzles.room.cowPushed = true;
}
And there's the code that tells the cow to goes -1 if the player don't click, but I don't know at all how to put this...
So, nothing is working with this code, so I assume I've done lot of mistakes.
Can you help me ?
Thank you very much for your help,
There is another error in the code
if (cow.y = 30)
should be
if (cow.y ==30);
maybe you have another one those in your code that causes the disturbance.
BTW: setTimeOut is considered even less trustworthy then Timers when it comes to actually measuring sth.
The code you provided rewriteen with a timer:
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
var clickTimer:Timer = new Timer(500);
var cowClicked:Boolean = false;
clickTimer.addEventListener(TimerEvent.TIMER,cl
...Copy link to clipboard
Copied
something like this?:
cow = new cowMovieclip;
addchild(cow);
cow.x = 0;
cow.y = 0;
cow.addEventListener(MouseEvent.CLICK, push, false, 0, true);
setTimeOut(pushCowBack, 500);
public function pushCowBack():void{if ( cow.x != 0 )
cow.x = cow.x - 2;
}
public function push(e:MouseEvent):void{
cow.x = +1;
cow.y = +1;
}
if (cow.y = 30){
allPuzzles.room.cowPushed = true;
}
Copy link to clipboard
Copied
Thank you !!
But error 1180 with the SetTimeOut...
I've put import flash.utils.*; but it doesn't change a thing...
Copy link to clipboard
Copied
My bad, the error is no longer here.
Copy link to clipboard
Copied
Hmm The game's launch.
The cow is at x=0 and y=0.
But, an error 1 second after I enter in the scene :
Error #1010: A term is undefined and has no properties.
at com.laserdragonuniversity.alpaca::Puzzle/pushCowBack()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at SetIntervalTimer/onTimer()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
In my puzzles, the line 2283 is "if ( cow.x != 0 )" in the pushCowBack function...
Any idea ?
Copy link to clipboard
Copied
There is another error in the code
if (cow.y = 30)
should be
if (cow.y ==30);
maybe you have another one those in your code that causes the disturbance.
BTW: setTimeOut is considered even less trustworthy then Timers when it comes to actually measuring sth.
The code you provided rewriteen with a timer:
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
var clickTimer:Timer = new Timer(500);
var cowClicked:Boolean = false;
clickTimer.addEventListener(TimerEvent.TIMER,clickTimeHandler);
clickTimer.start();
cow.addEventListener(MouseEvent.CLICK, clickHandler)
function clickTimeHandler(e:TimerEvent):void{
if(!cowClicked && cow.x>0){
cow.x -=5;
}
cowClicked = false;
}
function clickHandler(e:MouseEvent):void{
cowClicked = true;
cow.x += 5;
}
Copy link to clipboard
Copied
Thank you !