Jason,

I think you're on the right track with your custom component idea. I
think the best way to handle the dynamic data is with data binding. 

Let's take the image as an example. In the ActionScript of your custom
component, you declare a bindable public variable to hold the source
of your image:

[Bindable]
public var myImageSource:Class;

Also in your custom component, you place your image tag where you want
it, using binding syntax for your source attribute:
<mx:Image source="{myImageSource}" /> 

In your main MXML file, you set the value of the public variable to
the graphic asset that you want. For example, in the ActionScript of
the main file you might have something like this:

[Embed(source="assets/JoeSmith.png",mimeType="image/png")]
[Bindable]
public var myImageSource:Class;

Then, if you use MXML to load your custom component, you would write
something like this:
<myCustomComponent myImageSource="{myImageSource}" />

There are lots of variations on this theme (for example, you could do
it with all ActionScript and no MXML, etc.) but this is the basic idea. 

Data binding rocks.

HTH
-Jim

--- In flexcoders@yahoogroups.com, "Merrill, Jason"
<[EMAIL PROTECTED]> wrote:
>
> Newbie to Flex, (but not Flash/AS 2.0) so for me it's like a skier
> learning to snowboard.  I have dabbled with Flex in the past, and
> recently went through all the lessons in the help docs, as well as read
> a lot of other things in there. I'm designing a "Team Page" - a site
> that shows people of the business unit as individual "cards" - like
> baseball cards. Each card will have elements like a photo of the person,
> a description of skillsets, and buttons to expand and change to a
> different state. Making that is easy with a custom component, but I'm
> having some struggle with the dynamic data part as it relates to the
> custom component - in other words, making the components generic and
> then settings the data for them later in my application. 
> I thought I would make a generic "person card" with a placeholder for
> the photo and data - that would be a single component, and then in
> another main application MXML I would repeat that component over and
> over based on some XML data. Easy enough so far - the XML data isn't the
> problem. In Flex, I'm not sure how to add the image dynamically, or
> change the value of the image file reference for each component repeated
> - I can add an image tag easily enough in the component, but having a
> hard time not hard-coding the image reference.  So I guess I have a few
> questions: 
> 1. What's the best way to set up a generic image "container" for the
> image file be in the "person card" component and how would I set that in
> the main application MXML repeat region? Or is making the "person card"
> as a component not a good approach? Should I just describe the person
> card within the repeat region and not make it a custom component?
> 2. How do i set other variables in the custom components like label
> values? 
> 3. Overall, what would be a good way to architect a site like this? I
> know how to create and change states, but unsure what should be a
> component and what should just described right in the main MXML.
> 
> 
> Jason Merrill
> Bank of America  Learning & Organizational Effectiveness
> Multimedia / eTools Team
>


Reply via email to