To go back to your original example, it does seem a bit kludgy to me too. In
this case I would use databinding like so:

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"; width="500"
height="800">
<mx:Script>
<![CDATA[
[Bindable]
public var imageSource:String;
]]>
</mx:Script>
<mx:Panel x="100" y="100">
<mx:Image source="{imageSource}" x="10" y="10"/>
</mx:Panel>
</mx:Canvas>

If I'm making MXML components I often do stuff like that and just use
bindable public properties to pass through variables, which works well for
these simple cases.

Doug

On 1/13/08, Joseph Balderson <[EMAIL PROTECTED]> wrote:
>
>   If you are defining your component in MXML, then no, id cannot be
> private. When you define a component in MXML, the component class will
> inherit from whatever the main container class is, which in this case is
> Canvas. Canvas extends UIComponent, which defines the id attribute as
> being public. The only way to create a component with a private id
> attribute is to create the component in ActionScript, extend a subclass
> of UIcomponent, then override the id getter setter. And this goes for
> 'redefining' any built-in property of a UIComponent class.
>
> __________________________________________________________
>
> Joseph Balderson, Flash Platform Developer | http://joeflash.ca
> Writing partner, Community MX | http://www.communitymx.com
> Abobe Certified Developer & Trainer
>
>
> Merrill, Jason wrote:
> > When using your own custom made components in MXML, what is the best way
> > to easily set properties? I.e., say I have a simple component that has
> > an image inside a panel, and I want to set the image source in my MXML,
> > like this:
> >
> > <c:MyImageComponent imageSource="myPhoto.jpg" />
> >
> > The way I figured was to setup the component like this with a public
> > property - this works, but seems kinda kludgy - isn't there a more
> > preferred way (WITHOUT doing it all in Actionscript)?
> >
> > <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml";
> > width="500" height="800" creationComplete="update()">
> > <mx:Script>
> > <![CDATA[
> > public var imageSource:String;
> >
> > private function update():void
> > {
> > userPhotoImage.source = imageSource;
> > }
> > ]]>
> > </mx:Script>
> > <mx:Panel x="100" y="100">
> > <mx:Image id="userPhotoImage" x="10" y="10"/>
> > </mx:Panel>
> > </mx:Canvas>
> >
> > Bonus question - is there a way to make the component ids inside of the
> > main component private? (i.e., in the example above, make the id for
> > the <mx:Image> component private). Because when I see code hinting, I
> > see both the public property imageSource, but also the Image component's
> > id, "userPhotoImage", which I would prefer to keep private.
> >
> >
> >
> > Jason Merrill
> > Bank of America
> > GT&O L&LD Solutions Design & Development
> > eTools & Multimedia
> >
> > Bank of America Flash Platform Developer Community
> >
> >
> >
> >
> >
> >
> > --
> > Flexcoders Mailing List
> > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > Search Archives:
> http://www.mail-archive.com/flexcoders%40yahoogroups.com
> > Yahoo! Groups Links
> >
> >
> >
> >
>
>  
>

Reply via email to