Hi,
The below example for resize the sprite using the resize tab at the bottomright position. By using the tab button to resize the sprite as width and height and it cannot be allow to change the postion of x and y.Try the below example it very nice one for resize the sprite based on resize tab move position and updates its width and height.
The below example for resize the sprite using the resize tab at the bottomright position. By using the tab button to resize the sprite as width and height and it cannot be allow to change the postion of x and y.Try the below example it very nice one for resize the sprite based on resize tab move position and updates its width and height.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onInit()">
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
private var _spr:Sprite;
private var _rect:Rectangle;
private var _resizeTab:Sprite;
private function onInit():void
{
var ui:UIComponent = new UIComponent();
_spr = new Sprite();
_spr.graphics.clear();
_spr.graphics.beginFill(0xFF0000,0.5);
_spr.graphics.drawRect(0,0,200,200);
_spr.graphics.endFill();
ui.addChild(_spr);
addChild(ui);
ui.x = 50;
ui.y = 20;
_spr.addEventListener(MouseEvent.MOUSE_DOWN,onStartResize);
}
private function onStartResize(evt:MouseEvent):void
{
var _rect:Rectangle = _spr.getBounds(_spr.parent);
if(!_resizeTab)
{
_resizeTab = new Sprite();
_resizeTab.graphics.clear();
_resizeTab.graphics.beginFill(0x0000FF,0.8);
_resizeTab.graphics.drawRect(0,0,20,20);
_resizeTab.graphics.endFill();
_resizeTab.x = _rect.width - 10;
_resizeTab.y = _rect.height - 10;
_spr.addChild(_resizeTab);
_resizeTab.cacheAsBitmap = false;
_resizeTab.addEventListener(MouseEvent.MOUSE_DOWN,onResizeDown);
_resizeTab.addEventListener(MouseEvent.MOUSE_UP,onResizeUp);
}
else
return;
}
private function onResizeDown(evt:MouseEvent):void
{
var _sp:Sprite = evt.target.parent as Sprite;
_rect = _sp.getBounds(_sp.parent);
_resizeTab.startDrag();
addEventListener(MouseEvent.MOUSE_MOVE,onMove);
}
private function onMove(evt:MouseEvent):void
{
var _sp:Sprite = _resizeTab.parent as Sprite;
_rect.bottomRight = new Point(_sp.mouseX,_sp.mouseY);
_sp.graphics.clear();
_sp.graphics.beginFill(0xFF0000,0.4);
_sp.graphics.drawRect(0,0,_rect.width,_rect.height);
_sp.graphics.endFill();
var summa:Rectangle = _resizeTab.getBounds(_resizeTab.parent);
_resizeTab.x = _rect.width - (summa.width/2);
_resizeTab.y = _rect.height - (summa.height/2);
evt.updateAfterEvent();
}
private function onResizeUp(evt:MouseEvent):void
{
removeEventListener(MouseEvent.MOUSE_MOVE,onMove);
_resizeTab.stopDrag();
}
]]>
</mx:Script>
</mx:Application>
No comments:
Post a Comment