Posted on 2012-10-19 11:04
誰用我名字啦? 閱讀(211)
評論(0) 編輯 收藏 所屬分類:
flex學習之路
package
{
import flash.display.Sprite;
import flash.display.Shape;
import flash.events.Event;
import flash.events.MouseEvent;
public class dashias extends Sprite
{
private var mySprite1:Sprite = new Sprite();
private var mySprite2:Sprite = new Sprite();
public function dashias()
{
//畫圓
var circle:Shape = new Shape();
circle.graphics.lineStyle(0, 0x7B7B7B); //方法簽名: lineStyle(thickness, color)
circle.graphics.beginFill(0xFF0000);
circle.graphics.drawCircle(0, 0, 20);
circle.graphics.endFill();
//吧circle對象加入到舞臺中
mySprite1.addChild(circle);
this.addChild(mySprite1); //吧circle對象加入到舞臺中,this指stage
mySprite1.x = 100; //設置顯示列表構造對象mySprite的x坐標為100
mySprite1.y = 100; //設置顯示列表構造對象mySprite的y坐標為100
//畫線
var line:Shape = new Shape();
line.graphics.lineStyle(4, 0x00FF00);
line.graphics.lineTo(20, 20);
line.graphics.endFill();
line.x = 0;
line.y = 0;
mySprite2.addChild(line);
this.addChild(mySprite2);
mySprite2.x = 100;
mySprite2.y = 100;
//添加監聽事件
//ENTER_FRAME事件一位置Flash播放頭進入新的一幀,此時調用rotateRectObject偵聽器
mySprite2.addEventListener(Event.ENTER_FRAME, rotateRectObject);
//實現對mySprite1的拖拽
mySprite1.addEventListener(MouseEvent.MOUSE_UP, mouseReleased);
mySprite1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
//在mySprite1這個顯示列表基本構造元素上顯示手型鼠標光標
mySprite1.buttonMode = true;
mySprite1.useHandCursor = true;
}
function rotateRectObject(evt:Event):void {
//rotation si a property to rotate the respective object
mySprite2.rotation += 1;
}
function mouseDown(event:MouseEvent):void {
mySprite1.startDrag();
}
function mouseReleased(event:MouseEvent):void {
mySprite1.stopDrag();
}
}
}