forked from: Checkmate vol.5 Amateur
AS100本ノック
* 5回目のお題は「checkmateに挑戦」
* --
* 流されていくワンコ。。。
* さようなら、ワンコ。。。
* ドラッグしながらマウスを動かすと大量生産。。。
/**
* Copyright mex_ichikawa ( http://wonderfl.net/user/mex_ichikawa )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/txII
*/
// forked from checkmate's Checkmate vol.5 Amateur
/*
* AS100本ノック
* 5回目のお題は「checkmateに挑戦」
* --
* 流されていくワンコ。。。
* さようなら、ワンコ。。。
* ドラッグしながらマウスを動かすと大量生産。。。
*/
package {
import flash.display.*;
import flash.events.*;
import flash.geom.Point;
import flash.utils.*;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.easing.*;
import org.libspark.betweenas3.events.*;
import org.libspark.betweenas3.tweens.IObjectTween;
import org.libspark.betweenas3.tweens.ITween;
[SWF(width=465, height=465, backgroundColor=0xFFFFFF, frameRate=30)]
public class Amateur extends Sprite
{
public static const STAGE_WIDTH:uint = 465;
public static const STAGE_HEIGHT:uint = 465;
private static const DISTANCE_SIZE:uint = 60;
private var _isDown:Boolean;
private var _prePoint:Point;
private var _rect:Sprite;
public function Amateur()
{
init();
}
private function init():void
{
var r:Sprite = new Sprite();
r.graphics.beginFill(0x00A0E9, 0.4);
r.graphics.drawRect(0, STAGE_HEIGHT-15, STAGE_WIDTH, STAGE_HEIGHT);
addChild(r);
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
}
private function mouseDownHandler(event:MouseEvent):void
{
_isDown = true;
mouseMoveHandler(event);
}
private function mouseUpHandler(event:MouseEvent):void
{
_isDown = false;
_prePoint = null;
}
private function mouseMoveHandler(event:MouseEvent):void
{
var thisPoint:Point = new Point(event.stageX, event.stageY);
if(_isDown && (!_prePoint || Point.distance(thisPoint, _prePoint) > DISTANCE_SIZE))
{
var key:String = Wanco.keyList[Math.floor(Math.random() * Wanco.keyList.length)];
var wanco:Sprite = new Wanco(key);
_prePoint = thisPoint;
wanco.x = thisPoint.x;
wanco.y = thisPoint.y + wanco.height;
addChild(wanco);
var t:IObjectTween = BetweenAS3.physical(wanco, {y: STAGE_HEIGHT}, null, Physical.accelerate(0.4));
t.addEventListener(TweenEvent.COMPLETE, function(event:TweenEvent):void
{
var w:Wanco = event.target.target as Wanco;
w.scaleY = Math.random()/2 + 0.4;
makeTween(w).play();
});
t.play();
}
}
private function makeTween(targetObj:Wanco):ITween
{
var tg:Wanco = targetObj;
var t:ITween = BetweenAS3.parallel(
BetweenAS3.tween(
tg,
{x: -(tg.x)},
null,
tg.x/20 * 0.4,
Linear.easeNone
)
);
t.addEventListener(TweenEvent.UPDATE, function(event:TweenEvent):void
{
if(tg.currentFrame == 1)
{
tg.playMovie();
}
});
t.addEventListener(TweenEvent.COMPLETE, function(event:TweenEvent):void
{
tg.parent.removeChild(tg);
});
return t;
}
}
}
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.system.*;
import jp.progression.commands.*;
import jp.progression.commands.display.*;
import jp.progression.commands.lists.*;
import jp.progression.commands.net.*;
import jp.progression.commands.tweens.*;
import jp.progression.events.*;
class Wanco extends Sprite
{
public static var keyList:Array = [
'stay',
// 'jump',
// 'highJump',
'walk',
'run',
'squat',
'question',
'exclamation',
'heart',
'pout',
'star',
'sing',
'sleep'
// 'wake'
];
private static var GRAPHICS_URL:String = "http://swf.wonderfl.net/static/assets/checkmate05/wancoAmateur.swf";
private static var MOVIE_CLIPS:Array;
private var _mc:MovieClip;
private var _mcKey:String;
private var _isActive:Boolean;
public function Wanco(name:String)
{
_mcKey = name;
_isActive = false;
if(MOVIE_CLIPS == null)
{
MOVIE_CLIPS = [];
var com:SerialList = new SerialList();
com.addCommand(
new LoadSWF( new URLRequest( GRAPHICS_URL ) ),
function():void
{
var loader:Loader = Loader( this.latestData );
var domain:ApplicationDomain = loader.contentLoaderInfo.applicationDomain;
MOVIE_CLIPS['stay'] = domain.getDefinition( "StayMotion" ) as Class;
MOVIE_CLIPS['jump'] = domain.getDefinition( "JumpMotion" ) as Class;
MOVIE_CLIPS['highJump'] = domain.getDefinition( "HighJumpMotion" ) as Class;
MOVIE_CLIPS['walk'] = domain.getDefinition( "WalkMotion" ) as Class;
MOVIE_CLIPS['run'] = domain.getDefinition( "RunMotion" ) as Class;
MOVIE_CLIPS['squat'] = domain.getDefinition( "SquatMotion" ) as Class;
MOVIE_CLIPS['quest'] = domain.getDefinition( "QuestionMotion" ) as Class;
MOVIE_CLIPS['exclamation'] = domain.getDefinition( "ExclamationMotion" ) as Class;
MOVIE_CLIPS['heart'] = domain.getDefinition( "HeartMotion" ) as Class;
MOVIE_CLIPS['pout'] = domain.getDefinition( "PoutMotion" ) as Class;
MOVIE_CLIPS['star'] = domain.getDefinition( "StarMotion" ) as Class;
MOVIE_CLIPS['sing'] = domain.getDefinition( "SingMotion" ) as Class;
MOVIE_CLIPS['sleep'] = domain.getDefinition( "SleepMotion" ) as Class;
MOVIE_CLIPS['wake'] = domain.getDefinition( "WakeMotion" ) as Class;
}
);
com.addEventListener(ExecuteEvent.EXECUTE_COMPLETE, loadHandler);
com.execute();
}
else
{
loadHandler();
}
}
private function loadHandler(event:ExecuteEvent=null):void
{
if(typeof(MOVIE_CLIPS[_mcKey]) != 'undefined')
{
_mc = new MOVIE_CLIPS[_mcKey] as MovieClip;
addChild(_mc);
_isActive = true;
}
}
public function playMovie():void
{
if(_isActive)
{
_mc.gotoAndPlay(1);
_mc.wc2.wc3.gotoAndPlay(2);
}
}
public function get isActive():Boolean
{
return _isActive;
}
public function get currentFrame():uint
{
if(_isActive)
{
return _mc.wc2.wc3.currentFrame;
}
return 0;
}
}