4.11.10

Just for fun

Just for fun I decided to change up the jump program to work with event listeners, starting on the first of November. The final product is at this link. This version is different because instead of the green square being moved one interval and then stopping- based on the MouseEvent framework, the green square will be moved at multiple intervals based on Timers and TimerEvents.


Again here is the code that I am going to convert. It came from my Jump experiment. 
Red.addEventListener(MouseEvent.CLICK, RedJump);
function RedJump(event:MouseEvent):void


{
Green.x -= 60;
}
Blue.addEventListener(MouseEvent.CLICK, BlueJump);
function BlueJump(event:MouseEvent):void
{
Green.x +=60;
}
Yellow.addEventListener(MouseEvent.CLICK, YellowJump);
function YellowJump(event:MouseEvent):void
{
Green.y +=60;
}
Orange.addEventListener(MouseEvent.CLICK, OrangeJump);
function OrangeJump(event:MouseEvent):void
{
        Green.y -= 60;
}



I found the code for timers and timer events in the book and attempted to quickly retro-fit it for this operation. 


{
timer= new Timer(.4*1000, 3);
timer.addEventListener(TimerEvent.TIMER, timerStep);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerDone);
}
function timerStep(event:TimerEvent):void {
Green.x -= 20;
}
function timerDone(event:TimerEvent):void {
Green.x += 60;
}


I used the Timer and TimerEvent functions, starting with the red button only. The idea was to create a timer object that would count a certain number of milliseconds- in this case, four hundred- and then move the object a set distance- in this case, 20 pixels. I couldn't figure out a good use for the TIMER_COMPLETE event listener so I made it so that when the TIMER_COMPLETE event listener was clicked, the object would be sent back exactly the amount of pixels that it was moved.  


This is the code that I tried to implement:



{
timer= new Timer(.4*1000, 3);
timer.addEventListener(TimerEvent.TIMER, timerStep);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerDone);
}
function timerStep(event:TimerEvent):void {
Green.x -= 20;
}
function timerDone(event:TimerEvent):void {
Green.x += 60;
}



After implementing the code, I immediately received this error:



Scene 1, Layer 'Actions', Frame 1, Line 6 1120: Access of undefined property timer.
Scene 1, Layer 'Actions', Frame 1, Line 7 1120: Access of undefined property timer.
Scene 1, Layer 'Actions', Frame 1, Line 8 1120: Access of undefined property timer.


No comments:

Post a Comment