flash on 2012-3-30
♥0 |
Line 107 |
Modified 2012-03-31 07:28:43 |
MIT License
archived:2017-03-30 02:56:00
ActionScript3 source code
/**
* Copyright tepe ( http://wonderfl.net/user/tepe )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/6Tca
*/
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.geom.*;
import flash.net.*;
public class FlashTest extends Sprite {
private var s1:Sprite = new Sprite();
private var s2:Sprite = new Sprite();
private var s3:Sprite = new Sprite();
private var s4:Sprite = new Sprite();
private var s5:Sprite = new Sprite();
private var s6:Sprite = new Sprite();
private var field:Sprite = new Sprite();
private var zoom:Number = 1.0;
private var posX:Number = 0;
private var posY:Number = 0;
private var tf:TextField = new TextField();
private var so:SharedObject;
public function FlashTest() {
//一時データ作成
so = SharedObject.getLocal("test");
var flushStatus:String = so.flush();
addChild(field);
addChild(tf);
tf.text = "text";
s1.x = 100;
s1.y = 100;
s1.rotation += 20;
s1.scaleX = s1.scaleY = 1;
s1.graphics.beginFill(0x0000ff);
s1.graphics.drawRect(-20,-20,40,40);
s1.graphics.endFill();
field.addChild(s1);
s2.x = 0;
s2.y = 0;
s2.scaleX = s2.scaleY = 0.2;
s2.graphics.beginFill(0x00ffff);
s2.graphics.drawRect(0,0,40,40);
s2.graphics.endFill();
s1.addChild(s2);
with(s3){
x = 200;
y = 200;
//rotation = 50;
scaleX = scaleY = 1;
graphics.beginFill(0x000000,0.2);
graphics.drawRect(0,0,40,40);
graphics.endFill();
field.addChild(s3);
}
with(s4){
x = 200;
y = 200;
//rotation = 50;
scaleX = scaleY = 1;
graphics.beginFill(0xffaa00,0.2);
graphics.drawRect(0,0,40,40);
graphics.endFill();
field.addChild(s4);
}
with(s5){
x = 200;
y = 200;
//rotation = 50;
scaleX = scaleY = 1;
graphics.beginFill(0x00aa00,0.2);
graphics.drawRect(0,0,40,40);
graphics.endFill();
field.addChild(s5);
}
with(s6){
x = 200;
y = 200;
//rotation = 50;
scaleX = scaleY = 1;
graphics.beginFill(0xff00ff,0.9);
graphics.drawRect(0,0,40,40);
graphics.endFill();
}
addChild(s6);
tf.text = s1.x.toString() + " " + s1.width.toString();
addEventListener(Event.ENTER_FRAME,loop);
addEventListener(KeyboardEvent.KEY_DOWN,onKey);
}
private function loop(e:Event):void{
//field.scaleX = field.scaleY *= 1.001;
}
private function onKey(e:KeyboardEvent):void{
if(e.keyCode == 13){
//フィールド上のオブジェクト再配置
//オフセット値
var ox:Number = s1.x;
var oy:Number = s1.y;
var oScale:Number = s1.scaleX;
var oRot:Number = s1.rotation;
//フィールド位置をオブジェクトとのオフセット分移動
field.x += ox;
field.y += oy;
field.scaleX = field.scaleY *= oScale;
field.rotation += oRot;
//同じ尺度で他のオブジェクトも再配置
s3.x -= ox;
s3.y -= oy;
//s3.y -= ox * Math.sin(field.rotation* Math.PI / 180);
//s3.x -= oy * Math.cos(field.rotation* Math.PI / 180);
//s3.y *= Math.sin(oRot * Math.PI / 180);
//s3.x *= Math.cos(oRot * Math.PI / 180);
//s3.x /= oScale;
//s3.y /= oScale;
//s3.scaleX = s3.scaleY /= oScale;
//s3.rotation -= oRot;
s4.x -= ox;
s4.y -= oy;
//中心となるオブジェクト指定→オブジェクトをfieldのx:0,y:0,scale:1.0,rotate:0に配置
s1.x = 0; s1.y = 0; s1.scaleX = s1.scaleY = 1.0; s1.rotation = 0;
}
}
private function Rotate2(pt1:Point,alpha:Number):Point{
var pt2:Point = new Point();
pt2.x = pt1.x * Math.cos(alpha) - pt1.y * Math.sin(alpha);
pt2.y = pt1.x * Math.sin(alpha) + pt1.y * Math.cos(alpha);
return pt2;
}
}
}