PDA

View Full Version : passing a reference / variable to a Custom Component


ljonny18
08-07-2007, 09:03 AM
Hi, I was wondering if someone could help me.

It seems like a very simple problem but I cant for the life of me seem to work out a solution.


I have created a Custom Component that extends from the UIComponent that consists of a “rev counter” style clock face etc….
I want to use this component multiple times within my application – however feed it different data so for example each “rev counter” on the page will be displaying different data etc…..

I want to be able to reuse my component and not have to create a new component every time I add a “rev counter” to my application, therefore I need some way of passing a reference / variable to the component (maybe from the <mx /> tag where I declare it in the MXML code ??? )


<mx:Application …. xmlns:comps="components.*" …..>

<comps:RevCounterComp id=”” (add something here to reference???) />

</ mx:Application>


Doing this will allow me to reuse my ONE custom component MANY times feeding it different data (different data provaiders for each instance of the single component)

Hope this makes sense???

Any help / advice is much appreciated,

Thanks,
Jon.

dr_zeus
08-07-2007, 05:57 PM
You can add variables or properties to your custom component.

private var _myCustomProperty:String = "";

[Bindable]
public function get myCustomProperty():String
{
return this._myCustomProperty;
}

public function set myCustomProperty(value:String):void
{
this._myCustomProperty = value;
}

If your custom component is built in MXML, you'll need to put that in a <mx:Script> block.