如何将参数传递给用 ActionScript 编写的自定义组件 [英] How to pass parameter to Custom Component written in ActionScript
问题描述
我有一个用 ActionScript 编写的自定义组件.它有构造函数,它需要一些参数.
我想像这样在 mxml 中包含那个自定义组件,
Main.mxml
<预><代码>...<custom:CustomActionScriptComponent/>//错误行....但是,它显示了一个错误说
错误 1136:参数数量不正确.预期 1.
如何将 MXML 文件中的参数传递给该自定义 ActionScript 组件?
作为标签,MXML 不支持类构造器.
根据您的 ActionScript 类,您可以允许参数的默认初始化:
公共函数 CustomActionScriptComponent(parameter:Object=null){极好的();}
然后在您的 MXML 中实现创建完成事件处理程序:
<fx:脚本><![CDATA[导入 mx.events.FlexEvent;受保护的函数 creationCompleteHandler(event:FlexEvent):void{customActionScriptComponent.parameter = {};}]]></fx:脚本><custom:CustomActionScriptComponent id="customActionScriptComponent"/></s:应用程序>
I have a custom component written in ActionScript. It has constructor which is expecting some arguments.
I want to include that custom component in mxml like this,
Main.mxml
...
<custom:CustomActionScriptComponent/> // Error line ..
..
But, it shows me an error saying
Error 1136: Incorrect number of arguments. Expected 1.
How to pass parameter in MXML file, to that custom ActionScript component?
As tags, MXML does not support class constructors.
Per your ActionScript class, you could allow default initialization of the parameter:
public function CustomActionScriptComponent(parameter:Object=null)
{
super();
}
Then implement a creation complete event handler in your MXML:
<?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"
creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function creationCompleteHandler(event:FlexEvent):void
{
customActionScriptComponent.parameter = {};
}
]]>
</fx:Script>
<custom:CustomActionScriptComponent id="customActionScriptComponent" />
</s:Application>
这篇关于如何将参数传递给用 ActionScript 编写的自定义组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!