tags:

views:

16

answers:

1

I'd like to make a series of components into a solid, consistently repeatable object.

For example, suppose I have a "notification" template that I want to add to a notifications area every time something new happens. This template includes an icon (Image), text (label), and some space between these two things.

I want to take a template like that and make it so I can invoke it with a function like add_notification("icon", "text"). How would I go about doing that?

Thanks in advance.

+1  A: 

Create a mxml file for your component, e.g. MyComponent.mxml. Now you can do

var myComponent = new MyComponent()

and add that component to your notifications area.

To set the label text you could have this in MyComponent.mxml

[Bindable]
public var label:String;
...

<mx:Label text="{label}" />

and set the label with

myComponent.label = "something";

or you could drop the bindable variable and go with

myComponent.labelid.text = "something"

after giving your mx:Label an id attribute

rlovtang
Thanks, this worked pretty well... but I'm having trouble with the myComponent.labelid.property part. When I try to use it, I get an Error like "TypeError: Error #1009: Cannot access a property or method of a null object reference." :( The rest works well, though.
cookiecaper