flash on 2011-8-19
♥0 |
Line 143 |
Modified 2011-10-13 05:03:10 |
MIT License
archived:2017-03-20 04:05:23
ActionScript3 source code
/**
* Copyright cdubois75 ( http://wonderfl.net/user/cdubois75 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/i2Sg
*/
<?xml version="1.0" encoding="utf-8"?>
<!-- fxg/LibraryExample.mxml -->
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark"
creationComplete="initApp();">
<fx:Script>
<![CDATA[
import mx.core.FlexGlobals;
import spark.effects.Animate;
import mx.managers.DragManager;
import mx.core.DragSource;
import mx.events.DragEvent;
import flash.events.MouseEvent;
private function mouseMoveHandler(event:MouseEvent):void
{
var dragInitiator:Group=Group(event.currentTarget);
var ds:DragSource = new DragSource();
ds.addData(dragInitiator, "myRedBox");
DragManager.doDrag(dragInitiator, ds, event);
}
private function dragEnterHandler(event:DragEvent):void
{
if (event.dragSource.hasFormat("myRedBox"))
{
DragManager.acceptDragDrop(Canvas(event.currentTarget));
}
}
private function dragDropHandler(event:DragEvent):void
{
Group(event.dragInitiator).x = Canvas(event.currentTarget).mouseX;
Group(event.dragInitiator).y = Canvas(event.currentTarget).mouseY;
}
private function initApp():void
{
FlexGlobals.topLevelApplication.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
pnlApp.setFocus();
}
private function keyHandler(e:KeyboardEvent):void
{
pnlApp.title = "Flex FSX Example - Key Pressed: " + String(e.keyCode);
switch(e.keyCode)
{
case 37:
moveLeft.end();
fadeBlue.end();
fadeBlue.play();
moveLeft.play();
break;
case 38:
moveUp.end();
fadeBlue.end();
fadeBlue.play();
moveUp.play();
break;
case 39:
moveRight.end();
fadeBlue.end();
fadeBlue.play();
moveRight.play();
break;
case 40:
moveDown.end();
fadeBlue.end();
fadeBlue.play();
moveDown.play();
break;
}
}
private function changeRed():void
{
scRed.color==0xFF3333?scRed.color=0xFFFF00:scRed.color=0xFF3333;
}
]]>
</fx:Script>
<fx:Declarations>
<s:Animate id="scaleUp" target="{recYel}">
<s:SimpleMotionPath property="scaleX" valueFrom="1" valueTo="5"/>
<s:SimpleMotionPath property="scaleY" valueFrom="1" valueTo="5"/>
</s:Animate>
<s:Animate id="scaleDown" target="{recYel}">
<s:SimpleMotionPath property="scaleX" valueFrom="5" valueTo="1"/>
<s:SimpleMotionPath property="scaleY" valueFrom="5" valueTo="1"/>
</s:Animate>
<s:Animate id="moveUp" target="{grpBlue}">
<s:SimpleMotionPath property="y" valueFrom="{grpBlue.y}" valueTo="{grpBlue.y - 15}"/>
</s:Animate>
<s:Animate id="moveDown" target="{grpBlue}">
<s:SimpleMotionPath property="y" valueFrom="{grpBlue.y}" valueTo="{grpBlue.y + 15}"/>
</s:Animate>
<s:Animate id="moveRight" target="{grpBlue}">
<s:SimpleMotionPath property="x" valueFrom="{grpBlue.x}" valueTo="{grpBlue.x + 15}"/>
</s:Animate>
<s:Animate id="moveLeft" target="{grpBlue}">
<s:SimpleMotionPath property="x" valueFrom="{grpBlue.x}" valueTo="{grpBlue.x - 15}"/>
</s:Animate>
<s:Fade id="fadeBlue" target="{grpBlue}" alphaFrom=".5" alphaTo="1" />
</fx:Declarations>
<mx:Panel id="pnlApp" title="Flex FSX Example"
height="75%" width="75%">
<mx:Canvas height="100%" width="100%" backgroundColor="silver"
dragEnter="dragEnterHandler(event);"
dragDrop="dragDropHandler(event);">
<s:Graphic>
<s:Group mouseOut="scaleDown.end();scaleDown.play()"
mouseOver="scaleUp.end(); scaleUp.play()"
mouseMove="mouseMoveHandler(event)">
<s:Rect id="recYel" height="10" width="10">
<s:stroke>
<s:SolidColorStroke color="#000000" weight=".5"/>
</s:stroke>
<s:fill>
<s:SolidColor color="#FFFF00"/>
</s:fill>
</s:Rect>
</s:Group>
<s:Group id="grpBlue" x="20" mouseMove="mouseMoveHandler(event)">
<s:Rect height="10" width="10">
<s:stroke>
<s:SolidColorStroke color="#000000" weight=".5"/>
</s:stroke>
<s:fill>
<s:SolidColor color="#66CCFF"/>
</s:fill>
</s:Rect>
</s:Group>
<s:Group x="10" y="20" mouseOver="changeRed()"
mouseOut="changeRed()"
mouseMove="mouseMoveHandler(event)">
<s:Rect height="10" width="10">
<s:stroke>
<s:SolidColorStroke color="#000000" weight=".5"/>
</s:stroke>
<s:fill>
<s:SolidColor id="scRed" color="#FF3333"/>
</s:fill>
</s:Rect>
</s:Group>
</s:Graphic>
</mx:Canvas>
</mx:Panel>
</s:Application>