action_demo

by uranodai
♥18 | Line 96 | Modified 2010-04-16 02:33:38 | MIT License
play

ActionScript3 source code

/**
 * Copyright uranodai ( http://wonderfl.net/user/uranodai )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/aK2u
 */

package
{
	import com.bit101.components.PushButton;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.system.Security;
	
	[SWF(width="465",height="465",frameRate="24",backgroundColor="#FFFFFF")]
	
	public class action_demo extends Sprite
	{
		public var boston:Pet;
		
		public var btn1:PushButton;
		public var btn2:PushButton;
		public var btn3:PushButton;
		public var btn4:PushButton;
		public var btn5:PushButton;
		public var btn6:PushButton;
		public var btn7:PushButton;
		public var btn8:PushButton;
		public var btn9:PushButton;
		public var btn10:PushButton;
		public var btn11:PushButton;
		public var btn12:PushButton;
		
		
		public function action_demo()
		{
			boston = new Pet(PetURL.BOSTON);
			boston.x = 230;
			boston.y = 280;
			addChild(boston);
			boston.onLoad = onLoad;
		}
		
		public function onLoad():void
		{
			btn1 = new PushButton(this, 20,340, "sleep", onClick);
			btn2 = new PushButton(this, 130,340, "kamatte", onClick);
			btn3 = new PushButton(this, 240,340, "hoeru", onClick);
			btn4 = new PushButton(this, 350,340, "sit", onClick);
			btn5 = new PushButton(this, 20,370, "tatsu", onClick);
			btn6 = new PushButton(this, 130,370, "fuse", onClick);
			btn7 = new PushButton(this, 240,370, "joy", onClick);
			btn8 = new PushButton(this, 350,370, "sad", onClick);
			btn9 = new PushButton(this, 20,400, "dance", onClick);
			btn10 = new PushButton(this, 130,400, "horu", onClick);
			btn11 = new PushButton(this, 240,400, "flip", onClick);
			btn12 = new PushButton(this, 350,400, "buruburu", onClick);
		}
		
		public function onClick(e:Event):void
		{
			boston.playAction(PushButton(e.currentTarget).label);
		}
	}
}

import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;

class Pet extends Sprite
{
	public var onLoad:Function;
	private var current:MovieClip;
	private var urlLoader:URLLoader;
	private var loader:Loader;
	
	public function Pet(url:String)
	{
		urlLoader = new URLLoader();
		urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
		urlLoader.addEventListener(Event.COMPLETE, onLoad1);
		urlLoader.load(new URLRequest(url));	
	}
	
	private function onLoad1(e:Event):void
	{
		loader = new Loader();
		loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad2);
		loader.loadBytes(urlLoader.data);
	}
	
	private function onLoad2(e:Event):void
	{
		var clazz:Class = loader.contentLoaderInfo.applicationDomain.getDefinition("Pet") as Class;
		var pet:MovieClip = new clazz();
		pet.front.x = 0;
		pet.front.y = 0;
		addChild(pet.front);
		current = pet.front;
		if(onLoad != null) onLoad();
	}
	
	public function playAction(code:String):void
	{
		current.gotoAndPlay(code);
	}
}

class PetURL
{
	public static var BOSTON:String = "http://stat.ameba.net/training2010/boston.swf";
}

Forked