PDA

View Full Version : Passing arguments to a component


ruslan40
08-01-2009, 08:28 PM
Hello.

I have a very simple question about components; I tried searching here but couldn't find anything relevant.

I have a custom MXML/AS3 component to which I need to pass arguments. How can I do that when I integrate it into my application?

For example, in my application if I have:



<my:Component1 arg1="Test" arg2="{SampleArray}" />



How can I read the arg1 and arg2 from within the component?

Also, just a side question; What if I'm in the same situation, but the component I'm embedding is a pure AS3 component; is it possible to pass arguments to its constructor or alter public variables when embedding it using MXML?

Thank you in advance!

rebelheart
08-03-2009, 04:59 PM
To simply pass arguments use getters/setters.

private var _arg1:int;

public function get arg1():int
{
return _arg1;
}

public function set arg1(arg:int):void
{
_arg1= arg;
}

....}

from mxml access it as any other property of the component.

<component arg1="" />

check documentation for more details.