访问ascript文件中的MXML组件

时间:2011-07-29 10:01:33

标签: 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 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
  }
}

2 个答案:

答案 0 :(得分:0)

你为什么要在另一个班级处理这个活动?为什么eventhandler是静态的? 处理它发生的事件(index.mxml),然后调用另一个类的方法。

index.mxml中的eventhandler

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

答案 1 :(得分:0)

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

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

获得

event.currentTarget as IUIComponent。

在dragEnter函数中也是如此。