Posted on 2012-10-19 11:04
谁用我名字啦? 阅读(204)
评论(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();
}
}
}