flash on 2010-1-18
import flash.filters.DropShadowFilter;
/**
* Copyright muu ( http://wonderfl.net/user/muu )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/kPV6
*/
package{
import flash.display.Sprite;
import flash.text.TextField;
//import flash.filters.DropShadowFilter;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.*;
import flash.utils.setInterval;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.geom.Point;
import classes.*;
[SWF(backgroundColor="#FFFFFF", width="500", height="500", frameRate="30")]
public class Main extends Sprite {
private var speed:int = 10;
private var bound:int = 20;
private var mode:String = "move";
private var type:String = "bound";
private var type2:String = "brightness";
public var mc:Sprite;
public function Main() {
stage.scaleMode = StageScaleMode.NO_SCALE; //スケールモード変更
stage.align = StageAlign.TOP_LEFT; //座標基準を左上に
init();
}
private function init():void{
mc = new Sprite;//MakeMC(1 , 60 , 80 , 0x000000);
mc.graphics.beginFill(0x000000);
mc.graphics.drawCircle (0, 0, 30);
mc.graphics.endFill();
trace(stage.height)
addChild(mc);
mc.x = stage.stageWidth/2;
mc.y = stage.stageHeight/2;
stage.addEventListener(MouseEvent.CLICK,m_click);
mc.addEventListener(MouseEvent.ROLL_OVER , over);
mc.addEventListener(MouseEvent.ROLL_OUT , out);
}
private function m_click(event:MouseEvent):void {
var motion:Motion = new Motion();
if (mode == "move"){
motion.move ( type , mc , stage.mouseX , stage.mouseY , speed , bound );
}
}
private function over(event:MouseEvent):void {
var motion:Motion = new Motion();
//if (mode == "scale"){
motion.scale ( "bound" , mc , 2 , speed , bound );
//}
//if (mode == "color" && type2 == "brightness"){
// motion.color ( "brightness" , mc , 200 , 1 , 5);
//}
//if (mode == "color" && type2 == "alpha"){
// motion.color ( type2 , mc , -100 , 1 , 5);
//}
}
private function out(event:MouseEvent):void {
var motion:Motion = new Motion();
//if (mode == "scale"){
motion.scale ( "bound" , mc , 1 , speed , bound );
//}
//if (mode == "color" && type2 == "brightness"){
// motion.color ( "brightness" , mc , 1 , 200 , 5);
//}
//if (mode == "color" && type2 == "alpha"){
// motion.color ( type2 , mc , 1 , -100 , 5);
//}
}
}
}
import flash.display.Sprite;
//import flash.filters.DropShadowFilter;
import flash.events.Event;
import flash.display.*;
import flash.utils.setInterval;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.geom.Point;
import flash.geom.ColorTransform;
internal class Motion {
public var rot:Number = 0 ; // 速度
public var yurePos:Point; // 揺れ幅
public var yure:Number; // 弾みぐあい
public var dx:Number; //
public var dy:Number; //
public var sp:int;
public var targetPos:Point;
public var mc:Sprite;
public var type:int;
public var ts:Number;
public var defSC:Number;
public var sc:Number;
public var ds:Number;
public var zoom:Number;
public function Motion() {
}
public function move( type:String , targetMC:Sprite , targetX:Number , targetY:Number , speed:int , bound:int ):void {
mc = targetMC; // 動作対象
yure = bound; // 弾みぐあい
sp = speed; // 終了までの時間
targetPos = new Point(targetX + mc.x , targetY + mc.y);
targetPos = mc.globalToLocal(targetPos); //最終目標座標をローカルに変換
yurePos = new Point((targetPos.x - mc.x) , (targetPos.y - mc.y));
if( type == "back" ){
mc.addEventListener(Event.ENTER_FRAME,moveUp_start);
}else if ( type == "bound" ){
mc.addEventListener(Event.ENTER_FRAME,moveDown_start);
}
function moveUp_start(event:Event):void{
rot += yure; // 角度を変更
dx = (targetPos.x - yurePos.x); //x軸移動座標取得
dy = (targetPos.y - yurePos.y); //y軸移動座標取得
trace(yurePos.x + ":" + rot)
mc.x = dx;
mc.y = dy;
if(Math.abs(yurePos.x) > 0.1 || Math.abs(yurePos.y) > 0.1){ //揺れ幅の減算
yurePos.x = ( Math.cos( rot * Math.PI / 180) * yurePos.x)+yurePos.x/sp; //x軸移動座標取得
yurePos.y = ( Math.cos( rot * Math.PI / 180) * yurePos.y)+yurePos.y/sp; //y軸移動座標取得
}else{
mc.removeEventListener(Event.ENTER_FRAME,moveUp_start);
trace("end")
mc.x = targetPos.x;
mc.y = targetPos.y;
}
}
function moveDown_start(event:Event):void{
rot += yure; // 角度を変更
dx = (targetPos.x - Math.cos( rot * Math.PI / 180) * yurePos.x); //x軸移動座標取得
dy = (targetPos.y - Math.cos( rot * Math.PI / 180) * yurePos.y); //y軸移動座標取得
trace(yurePos.x + ":" + rot)
mc.x = dx;
mc.y = dy;
if(Math.abs(yurePos.x) > 0.5 || Math.abs(yurePos.y) > 0.5){ //揺れ幅の減算
yurePos.x -= yurePos.x/sp;
yurePos.y -= yurePos.y/sp;
}else{
mc.removeEventListener(Event.ENTER_FRAME,moveDown_start);
trace("end")
mc.x = targetPos.x;
mc.y = targetPos.y;
}
}
}
public function scale( type:String , targetMC:Sprite , targetSC:Number , speed:int , bound:int ):void {
sc = targetSC;
ts = targetSC;
mc = targetMC; // 動作対象
defSC = mc.scaleX; // 初期位置X
yure = bound; // 弾みぐあい
sp = speed; // 終了までの時間
zoom = (sc - defSC); //目標までの差
//if( defSC <= 2 && defSC >= 1 ){
if( type == "back" ){
mc.addEventListener(Event.ENTER_FRAME,scaleUp_start);
}else if ( type == "bound" ){
mc.addEventListener(Event.ENTER_FRAME,scaleDown_start);
}
//}
function scaleUp_start(event:Event):void{
rot += yure; // 角度を変更
ds = ts - zoom;
mc.scaleX = mc.scaleY = ds;
if(Math.abs(zoom) > 0.01 ){ //揺れ幅の減算
zoom = ( Math.cos( rot * Math.PI / 180) * zoom)+zoom/sp; //x軸移動座標取得
}else{
mc.removeEventListener(Event.ENTER_FRAME,scaleUp_start);
trace("end")
mc.scaleX = mc.scaleY = ts;
}
}
function scaleDown_start(event:Event):void{
rot += yure; // 角度を変更
ds = (ts - Math.cos( rot * Math.PI / 180) * zoom); //x軸移動座標取得
mc.scaleX = mc.scaleY = ds;
if(Math.abs(sc) > 0.01){ //揺れ幅の減算
zoom -= zoom/sp;
}else{
mc.removeEventListener(Event.ENTER_FRAME,scaleDown_start);
trace("end")
mc.scaleX = mc.scaleY = ts;
}
}
}
public function color( type:String , targetMC:Sprite , point:int , def:int , speed:int ):void {
mc = targetMC; // 動作対象
sp = speed; // 終了までの時間
var pt:int = def;
var color:ColorTransform;
mc.addEventListener(Event.ENTER_FRAME,brightness_start);
function brightness_start(event:Event):void{
if( type == "brightness" ){
color = new ColorTransform(1,1,1,1,pt,pt,pt,1);
}else if ( type == "alpha" ){
color = new ColorTransform(1,1,1,1,1,1,1,pt);
}
mc.transform.colorTransform = color;
if ( Math.abs(pt - point ) > 10 ){
pt += (point - pt)/sp;
}else{
pt = point;
trace("end");
mc.removeEventListener(Event.ENTER_FRAME,brightness_start);
}
}
}
}