Meaningless Drivel is fun!*
The moose likes Flex and the fly likes accessing custom components within a container from mxml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Flex
Bookmark "accessing custom components within a container from mxml" Watch "accessing custom components within a container from mxml" New topic
Author

accessing custom components within a container from mxml

Satchit Talla
Greenhorn

Joined: Nov 26, 2002
Posts: 10
I have custom components that are added as "SkinParts" in a class that extends "SkinnableContainer". Would I be able to access the child components'(that are added as "skinParts") properties from the MXML file?

Thanks,
Satchit
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You should be. It depends how you've written your custom components.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Satchit Talla
Greenhorn

Joined: Nov 26, 2002
Posts: 10
These my components classes and the container class that contains the custom componets:



Second component:


The container class that contains the above components:

Given the above, would I be able to access the properties of components from the MXML file? Can you give me an example if you would?

Thanks,
Satchit
Dan Orlando
author
Ranch Hand

Joined: Mar 04, 2010
Posts: 31
Well, by using SkinnableContainer objects as SkinParts, you're nesting containers, which isn't generally a great practice. SkinnableContainer is also a lot heavier than - say - Group, for example. This kind of situation sometimes cannot be avoided though. In this instance, your best bet is to put properties in the parent containers that correspond to the children's properties that you need access to. We refer to these parent containers as "composite" components, as opposed to "simple" components. Composites are containers that hold any number of controls. In your example, let's say you needed access to the value of name.text, where name is a TextInput in the Identity object, as your code shows. In your WidgetToolbarComponent, place the following code:

================================
private var _identityNameText:String;

public function get identityNameText():String
{
return identity.name.text;
}

[Bindable]
public function set identityNameText(value:String):void
{
identity.name.text = value;
}
==================================

Then, in your MXML, you can set the text of the name TextInput in the Identity skin part like so:

<component:WidgetToolbarComponent id="toolbar" identityNameText="This will appear in Identity's name text input" />

Cheers!




Dan Orlando
Adobe Community Professional
Author, Flex 4 in Action (Manning Press)
Satchit Talla
Greenhorn

Joined: Nov 26, 2002
Posts: 10
Dan,
Thanks for your response. Just to make sure, I wasn't using skinnableContainers as skinParts. They are just custom components(skinnableComponents). But, I do get your suggestion of the way I should be accessing. So, let us say if I change my container that contains other custom components to SkinnableComponent(using composite component), I should be able to access the custom components from a composite component by using the "bindable" for the properties? Please let me know if that would work in my situation.

Good luck with the new book. Still waiting for it to come out so I can buy. Has been a long wait!
Dan Orlando
author
Ranch Hand

Joined: Mar 04, 2010
Posts: 31
Satchit Talla wrote:Dan,
Thanks for your response. Just to make sure, I wasn't using skinnableContainers as skinParts. They are just custom components(skinnableComponents). But, I do get your suggestion of the way I should be accessing. So, let us say if I change my container that contains other custom components to SkinnableComponent(using composite component), I should be able to access the custom components from a composite component by using the "bindable" for the properties? Please let me know if that would work in my situation.

Good luck with the new book. Still waiting for it to come out so I can buy. Has been a long wait!


Sorry, my mistake. SkinnableContainer and SkinnableComponent look a lot like, so I must have glanced over it to quickly and thought they were all SkinnableContainers. There actually isn't much difference between the two, with SkinnableContainer sub-classing SkinnableComponent, so that doesn't change anything with regard to my response. It should still work the same if you use the methodology I described. Let me know if you have any issues with it or run into anything strange via this thread and I'll keep an eye on it.
Satchit Talla
Greenhorn

Joined: Nov 26, 2002
Posts: 10
Thank you. Seems to be working. Thanks again!
 
 
subject: accessing custom components within a container from mxml
 
Similar Threads
Calling one mxml file from another
Navigate from one mxml to another mxml
Reloading custom mxml component
Flex 3: Appropiate way for creating a Module Component
How will XML change the software industry?