お菓子をくれなきゃ、いたずらするぞ! Trick or Treat!
ということで、ハロウィン。ActionScript 3.0を使って10分ほどで作成。カボチャをクリックすると色が変わる。
以下に、ソースコードを示す。
Halloween.as
// Halloween.as // by nox, 2008.10.31 package { import flash.display.*; import flash.text.*; import flash.events.*; import flash.utils.Timer; public class Halloween extends Sprite { // dafont.com http://www.dafont.com/ [Embed(systemFont="Halloween Borders", fontName="HalloweenFont", mimeType="application/x-font" )] private static const HalloweenFont:Class; private var txtHalloween:TextField = new TextField(); private var HalloweenStageWidth:int, HalloweenStageHeight:int; private var timer:Timer; private function ClickHandler(event:Event):void { var format:TextFormat = txtHalloween.getTextFormat(); format.color = Math.random() * 0xFFFFFF; txtHalloween.setTextFormat(format); } private function OnTick(event:TimerEvent):void { txtHalloween.x += (Math.random() - 0.5) * 2; txtHalloween.y += (Math.random() - 0.5) * 2; } private function Init():void { var format:TextFormat = new TextFormat(); with (format) { color = 0xCC0000; size = 144; align = TextFormatAlign.CENTER; font = "HalloweenFont"; } with (txtHalloween) { autoSize = TextFieldAutoSize.CENTER; selectable = false; x = HalloweenStageWidth / 2; embedFonts = true; defaultTextFormat = format; text = "e"; y = (HalloweenStageHeight - textHeight) / 2; } addChild(txtHalloween); txtHalloween.addEventListener(MouseEvent.CLICK, ClickHandler); timer = new Timer(10); timer.addEventListener(TimerEvent.TIMER, OnTick); timer.start(); } public function Halloween() { HalloweenStageWidth = stage.stageWidth; HalloweenStageHeight = stage.stageHeight; Init(); } } }
Halloween-config.xml
<flex-config> <output>Halloween.swf</output> <default-size> <width>150</width> <height>150</height> </default-size> <default-frame-rate>60</default-frame-rate> <default-background-color>0xFFFFFF</default-background-color> <use-network>false</use-network> </flex-config>
ということで、ハロウィン。ActionScript 3.0を使って10分ほどで作成。カボチャをクリックすると色が変わる。
以下に、ソースコードを示す。
Halloween.as
// Halloween.as // by nox, 2008.10.31 package { import flash.display.*; import flash.text.*; import flash.events.*; import flash.utils.Timer; public class Halloween extends Sprite { // dafont.com http://www.dafont.com/ [Embed(systemFont="Halloween Borders", fontName="HalloweenFont", mimeType="application/x-font" )] private static const HalloweenFont:Class; private var txtHalloween:TextField = new TextField(); private var HalloweenStageWidth:int, HalloweenStageHeight:int; private var timer:Timer; private function ClickHandler(event:Event):void { var format:TextFormat = txtHalloween.getTextFormat(); format.color = Math.random() * 0xFFFFFF; txtHalloween.setTextFormat(format); } private function OnTick(event:TimerEvent):void { txtHalloween.x += (Math.random() - 0.5) * 2; txtHalloween.y += (Math.random() - 0.5) * 2; } private function Init():void { var format:TextFormat = new TextFormat(); with (format) { color = 0xCC0000; size = 144; align = TextFormatAlign.CENTER; font = "HalloweenFont"; } with (txtHalloween) { autoSize = TextFieldAutoSize.CENTER; selectable = false; x = HalloweenStageWidth / 2; embedFonts = true; defaultTextFormat = format; text = "e"; y = (HalloweenStageHeight - textHeight) / 2; } addChild(txtHalloween); txtHalloween.addEventListener(MouseEvent.CLICK, ClickHandler); timer = new Timer(10); timer.addEventListener(TimerEvent.TIMER, OnTick); timer.start(); } public function Halloween() { HalloweenStageWidth = stage.stageWidth; HalloweenStageHeight = stage.stageHeight; Init(); } } }
Halloween-config.xml
<flex-config> <output>Halloween.swf</output> <default-size> <width>150</width> <height>150</height> </default-size> <default-frame-rate>60</default-frame-rate> <default-background-color>0xFFFFFF</default-background-color> <use-network>false</use-network> </flex-config>
コメント