开发者

flex pass parameter to custom component

开发者 https://www.devze.com 2023-02-10 11:28 出处:网络
I have a cus开发者_如何学Gotom component written in action script (no UI). I am instantiating this component in an mxml file which is present in a library project. The custom component has a construct

I have a cus开发者_如何学Gotom component written in action script (no UI). I am instantiating this component in an mxml file which is present in a library project. The custom component has a constructor which takes one argument.

The library project is used in some other web project from where i pass a variable to this mxml file.[I have linked source of the web project to source of library.].

I have a static variable in my library project which holds the reference of the current object of the project. I need this static variable in order to use properties present in the mxml file.

I am unable to use the property sent from the web project in the constructor of the custom component, but able to use the same in some other function present in the custom component.

Please help me!

Thanks

Anji


if you are able to access the value you need from mxml:
mxml code:

<local:MyComponent varname="value"/>

AS3 code:

private var _varname:Type;
public function MyComponent(){
    //empty constructor
}
public function set varname(newVal: Type):void{
    _varname = newVal;
    //constructor code here
}

else you'll have to find the MyComponent event that is fired when the variable you need is already accessible (e.g. CREATION_COMPLETE):
AS3 code:

public function MyComponent() {
    addEventListener(FlexEvent.CREATION_COMPLETE, onCreated);
}

private function onCreated(e:FlexEvent):void {
    //access of the variable and constructor code
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号