本文介绍了如何通过参数来定制组件ActionScript编写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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>

这篇关于如何通过参数来定制组件ActionScript编写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 08:48