Flash / Flex / ActionScript/TextField/Animation — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 11:14, 26 мая 2010
Содержание
- 1 Animating a TextField horizontally to x-coordinate 300
- 2 Animating a TextField horizontally to x-coordinate 300, timer version
- 3 Frame Rate"s Effect on Event.ENTER_FRAME Animations
- 4 Timer event
- 5 To eliminate unnecessary function calls, we unregister moveTextRight( ) for Event.ENTER_FRAME events.
Animating a TextField horizontally to x-coordinate 300
<source lang="java">
package {
import flash.display.*; import flash.events.*; import flash.text.*; public class Main extends Sprite { private var t:TextField = new TextField( ); public function Main ( ) { t.text = "Hello"; t.autoSize = TextFieldAutoSize.LEFT; addChild(t); addEventListener(Event.ENTER_FRAME, moveTextRight); } public function moveTextRight (e:Event):void { if (t.x <= 300) { t.x += 10; if (t.x > 300) { t.x = 300; } } else { removeEventListener(Event.ENTER_FRAME, moveTextRight); } } }
}
</source>
Animating a TextField horizontally to x-coordinate 300, timer version
<source lang="java">
package {
import flash.display.*; import flash.events.*; import flash.utils.*; import flash.text.*; public class Main extends Sprite { private var t:TextField = new TextField( ); private var timer:Timer; public function Main( ) { t.text = "Hello"; t.autoSize = TextFieldAutoSize.LEFT; addChild(t); timer = new Timer(50, 0); timer.addEventListener(TimerEvent.TIMER, moveTextRight); timer.start( ); } public function moveTextRight (e:TimerEvent):void { if (t.x <= 300) { t.x += 10; if (t.x > 300) { t.x = 300; } e.updateAfterEvent( ); // Update the screen following this function } else { timer.stop( ); } } }
}
</source>
Frame Rate"s Effect on Event.ENTER_FRAME Animations
<source lang="java">
package {
import flash.display.*; import flash.events.*; import flash.utils.*; import flash.text.*; public class Main extends Sprite { private var startMsg:TextField = new TextField( ); public function Main( ) { var timer:Timer = new Timer(3000, 1); timer.addEventListener(TimerEvent.TIMER, timerListener); timer.start( ); startMsg.autoSize = TextFieldAutoSize.LEFT; startMsg.text = "Get Ready!"; addChild(startMsg); } private function timerListener (e:TimerEvent):void { startMsg.text = "GO!"; } }
}
</source>
Timer event
<source lang="java">
package {
import flash.display.TextField; import flash.util.Timer; import flash.events.*; public class BlinkText extends TextField { private var timer:Timer; public function BlinkText (delay:Number = 1000) { timer = new Timer(delay, 0); timer.addEventListener(TimerEvent.TIMER, timerListener); timer.start( ); } private function timerListener (e:TimerEvent):void { visible = !visible; e.updateAfterEvent( ); } public function setDelay (newDelay:Number):void { timer.delay = newDelay; } public function startBlink ( ):void { timer.start( ); } public function stopBlink ( ):void { visible = true; timer.stop( ); } }
}
</source>
To eliminate unnecessary function calls, we unregister moveTextRight( ) for Event.ENTER_FRAME events.
<source lang="java">
package{
import flash.display.*; import flash.text.*; import flash.events.*; public class Main extends Sprite { private var t:TextField = new TextField( ); public function Main ( ) { t.text = "Hello"; t.autoSize = TextFieldAutoSize.LEFT; addChild(t); addEventListener(Event.ENTER_FRAME, moveTextRight); } public function moveTextRight (e:Event):void { if (t.x <= 300) { t.x += 10; if (t.x > 300) { t.x = 300; } } else { removeEventListener(Event.ENTER_FRAME, moveTextRight); } } }
}
</source>