Apache flex 访问ascript文件中的MXML组件

Apache flex 访问ascript文件中的MXML组件,apache-flex,flex4,Apache Flex,Flex4,如何绕过以下错误:访问未定义的属性pMatrixBack 如何从ascript文件中访问此组件 // src/index.mxml <s:Application> <s:Group id="iMatrix" width="100%" height="100%" dragEnter="WorkRows.acceptEnterHandler(event)" dragDrop="xyz.action(event)"> <assets:PMatrixBack

如何绕过以下错误:访问未定义的属性pMatrixBack 如何从ascript文件中访问此组件

// src/index.mxml

<s:Application>
  <s:Group id="iMatrix" width="100%" height="100%" dragEnter="WorkRows.acceptEnterHandler(event)" dragDrop="xyz.action(event)">
    <assets:PMatrixBack id="pMatrixBack" width="100%" height="100%"/>
  </s:Group>
</s:Application>

// src/ascript/xyz.as

package xyz
{
  static public function action(event:DragEvent):void
  {
    var bitmap:BitmapData = ImageSnapshot.captureBitmapData(pMatrixBack); //Error
  }
}
//src/index.mxml
//src/ascript/xyz.as
包装xyz
{
静态公共函数操作(事件:DrageEvent):无效
{
变量位图:BitmapData=ImageSnapshot.captureBitmapData(pMatrixBack);//错误
}
}

您为什么要在另一个类中处理该事件?为什么eventhandler是静态的? 处理发生的事件(index.mxml),然后调用另一个类的方法

index.mxml中的eventhandler

private function onAction(evt:DragEvent):void
{
    // you can access pMatrixBack here
    myObj.doSomethingWithPMatrix(pMatrixBack);
}

首先检查是否创建了xyz对象

您不能直接访问,您只能通过

event.currentTarget作为IUIComponent


在dragEnter函数中也是如此。

var group:group=event.currentTarget as group;变量组:组=事件。当前目标为组;位图=ImageSnapshot.captureBitmapData(组.getElementAt(0)为IBitMapable);这对我有用。