Test for frog
//////////////////////////////////////////////////////////////////////////////
Test for frog
かえる君のためのテスト
サウンドがあまり奇麗に出なくてごめんなさい。
//////////////////////////////////////////////////////////////////////////////
/**
* Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9TxR
*/
////////////////////////////////////////////////////////////////////////////////
// Test for frog
// かえる君のためのテスト
//
// サウンドがあまり奇麗に出なくてごめんなさい。
////////////////////////////////////////////////////////////////////////////////
package {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.system.Security;
[SWF(backgroundColor="#FFFFFF", width="465", height="465", frameRate="30")]
public class Main extends Sprite {
private var loader:FrogLoader;
private static var frogPath:String = "http://www.project-nya.jp/images/flash/frogA.swf";
private var frog:MovieClip;
public function Main() {
Wonderfl.capture_delay(1);
init();
}
private function init():void {
loader = new FrogLoader();
loader.addEventListener(FrogLoader.COMPLETE, complete, false, 0, true);
loader.load(frogPath);
}
private function complete(evt:Event):void {
loader.removeEventListener(FrogLoader.COMPLETE, complete);
frog = loader.content;
addChild(frog);
frog.x = 232;
frog.y = 350;
frog.addEventListener(Event.COMPLETE, jumped, false, 0, true);
frog.buttonMode = true;
frog.addEventListener(MouseEvent.MOUSE_OVER, over, false, 0, true);
frog.addEventListener(MouseEvent.CLICK, click, false, 0, true);
}
private function over(evt:MouseEvent):void {
frog.swingHead();
}
private function click(evt:MouseEvent):void {
frog.removeEventListener(MouseEvent.CLICK, click);
frog.jump();
}
private function jumped(evt:Event):void {
frog.addEventListener(MouseEvent.CLICK, click, false, 0, true);
}
}
}
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.HTTPStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.system.Security;
class FrogLoader extends Sprite {
private var loader:Loader;
private var info:LoaderInfo;
public var content:MovieClip;
public static const IO_ERROR:String = IOErrorEvent.IO_ERROR;
public static const HTTP_STATUS:String = HTTPStatusEvent.HTTP_STATUS;
public static const SECURITY_ERROR:String = SecurityErrorEvent.SECURITY_ERROR;
public static const INIT:String = Event.INIT;
public static const COMPLETE:String = Event.COMPLETE;
public function FrogLoader() {
Security.allowDomain("www.project-nya.jp");
loader = new Loader();
info = loader.contentLoaderInfo;
}
public function load(file:String):void {
info.addEventListener(IOErrorEvent.IO_ERROR, ioerror, false, 0, true);
info.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpstatus, false, 0, true);
info.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityerror, false, 0, true);
info.addEventListener(Event.INIT, initialize, false, 0, true);
info.addEventListener(Event.COMPLETE, complete, false, 0, true);
try {
loader.load(new URLRequest(file));
} catch (err:Error) {
trace(err.message);
}
}
public function unload():void {
loader.unload();
}
private function ioerror(evt:IOErrorEvent):void {
loader.unload();
dispatchEvent(new Event(FrogLoader.IO_ERROR));
}
private function httpstatus(evt:HTTPStatusEvent):void {
dispatchEvent(new Event(FrogLoader.HTTP_STATUS));
}
private function securityerror(evt:SecurityErrorEvent):void {
dispatchEvent(new Event(FrogLoader.SECURITY_ERROR));
}
private function initialize(evt:Event):void {
content = MovieClip(info.content);
dispatchEvent(new Event(FrogLoader.INIT));
}
private function complete(evt:Event):void {
info.removeEventListener(IOErrorEvent.IO_ERROR, ioerror);
info.removeEventListener(HTTPStatusEvent.HTTP_STATUS, httpstatus);
info.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, securityerror);
info.removeEventListener(Event.INIT, initialize);
info.removeEventListener(Event.COMPLETE, complete);
//addChild(loader);
dispatchEvent(new Event(FrogLoader.COMPLETE));
}
}