如何使用参数制作 MXML 组件构造函数? [英] How to make MXML Component Constructor with Arguments?

查看:34
本文介绍了如何使用参数制作 MXML 组件构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 flex 新手,有人可以帮我吗?

I`m new in flex and could anyone help me?

如何创建一个接受 MXML 组件参数的构造函数?

How do I create a constructor that takes arguments for an MXML component?

推荐答案

你不能;MXML 组件没有可以修改的构造函数.

You can't; MXML Components do not have constructors that you can modify.

您有几个选择.第一个是重写您的组件以使用 ActionScript.这在某些情况下可能是乏味的,而在其他情况下则是微不足道的.这取决于组件的作用.

You have a few options. The first is to rewrite your component to use ActionScript. This can be tedious in some situations, and trivial in others. It depends what the component does.

第二个选项 os 在组件上使用公共变量.创建 MXML 组件的实例时,请为其设置属性.您应该能够在预初始化事件处理程序中访问这些属性.prenitinialize 将在构造函数之后调度,但在 createChildren() 之前.

A second option os to use public variables on the component. When you create the instance of your MXML Component, set the properties on it. You should be able to access such properties in a preinitialize event handler. prenitinialize will be dispatched after the constructor, but before createChildren().

这篇关于如何使用参数制作 MXML 组件构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆