Flex 图片缩放、托拽效果
时间:2011-06-11 来源:小小池
layout="absolute" width="800" height="500" applicationComplete="app(event)" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
protected function app(event:FlexEvent):void
{
img.addEventListener(MouseEvent.MOUSE_DOWN, imgMouseDown);
img.addEventListener(MouseEvent.MOUSE_UP, imgMouseUp);
this.addEventListener(MouseEvent.MOUSE_WHEEL, imgZoom);//滚动事件
}
private function imgMouseDown(evt:MouseEvent):void
{
evt.currentTarget.startDrag();
}
private function imgMouseUp(evt:MouseEvent):void
{
evt.currentTarget.stopDrag();
}
private function imgZoom(evt:MouseEvent):void
{
var w:Number = img.width * evt.delta * 0.02;
var h:Number = img.height * evt.delta * 0.02;
img.x += -w/2;
img.y += -h/2;
img.width += w;
img.height += h;
//Alert.show(img.width.toString());
}
]]>
</mx:Script>
<mx:Image x="70" y="85" id="img" source="1.jpg"/>
</mx:Application>
相关阅读 更多 +