Skip to main content
Participating Frequently
December 6, 2009
Question

Getting reference of a dynamic instancied part

  • December 6, 2009
  • 1 reply
  • 524 views

Hi,

I'd like to know what is the best practice about getting a reference of a dynamic instancied part.

Here is a use case:

Definition of my dynamic SkinPart:

[SkinPart(type="spark.components.Group")]
public var minutesGroup:IFactory;

Somewhere in my code, I need to acces the instancied group.

At the moment , I have something really ugly that looks like this :

HorizontalLayout(Group(dropDown.getChildByName("minutesGroup")).layout).paddingLeft = _selectedHour.x;

Not only this is unreadable but will slow down my application.

So how do you think I should handle this?

Should I create a instanciedMinutesGroup class variable that gets a reference of the Group?

(something like :

instanciedMinutesGroup = createDynamicPartInstance("minutesGroup") as Group; )

I guess this is a better solution that the one I'm using for now,  but I will have at some time, 3 or 4 dynamic parts and creating a class variable for each part seems inappropriate.

Also, I see there is a getDynamicaPartAt method but I won't know what is the index of that part.

Any help welcomed!

This topic has been closed for replies.

1 reply

December 7, 2009

You could store it like:

instanciedMinutesGroup = createDynamicPartInstance("minutesGroup") as Group;

Or, you could use getDynamicPartAt().  If you're only creating one of these groups, as it sounds like you are, then the index you pass in will always be 0.  If you're creating multiple "minuteGroups", then the index in to the "list of minuteGroups".  You have to send in an index here because you have to be able to distinguish between which minuteGroup you want, so you've got to figure out how to keep track of it in your code.

Hope that helps,

Ryan

Participating Frequently
December 7, 2009

Yes, it helps, a lot. Thanks

I've almost finished my first spark component and I'm really impressed about the new architecture.

I'll probably post it here once it's finished