[英]AS3 and Flex 4 - Applying AS3 Class to Flex mxml file
我这里有这个AS3类,可以检测鼠标是否移动了:
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class ApplicationTimer extends Sprite
{
public function ApplicationTimer()
{
stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoved);
}
public function mouseMoved(event:MouseEvent):void
{
trace("mouse moved")
}
}
}
我要做的是将此类应用于我的主要mxml Flex文件,这样当我的鼠标在我的项目中移动时,将调用mouseMoved方法。 我该怎么做?
MXML文件已经是一个类,您可以向它们添加脚本。 您不能直接使用您的类,因为MXML使用flex体系结构,而MXML Component需要扩展UIComponent,而不是Sprite。
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
mouseMove="mouseMoveHandler(event)">
<fx:Script>
<![CDATA[
protected function mouseMoveHandler(event:MouseEvent):void
{
trace(event);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:Application>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.