由网友(卿弦季鸢)分享简介:我有ActionScript编写的自定义组件。它有构造函数期待一些参数。I have a custom component written in ActionScript. It has constructor which is expecting some arguments.我希望包括自定义组件在MXML这样,...
我有ActionScript编写的自定义组件。它有构造函数期待一些参数。
I have a custom component written in ActionScript. It has constructor which is expecting some arguments.
我希望包括自定义组件在MXML这样,
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.
如何通过参数MXML文件,该自定义动作成分?
How to pass parameter in MXML file, to that custom ActionScript component?
推荐答案
作为标签,MXML并不支持类的构造函数。
As tags, MXML does not support class constructors.
按照您的ActionScript类,可以允许参数的默认初始化:
Per your ActionScript class, you could allow default initialization of the parameter:
public function CustomActionScriptComponent(parameter:Object=null)
{
super();
}
然后实现一个创造完整的事件处理程序在MXML:
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>
相关推荐
最新文章