It may be true that it's not intended to be described as MXML, but it does work, since you can't add sprites directly to containers like panels, you have to add them to UIComponents first, I used a UIComponent MXML tag elsewhere in my app to add a Sprite and it worked just fine. So I don't think that's it. I could declare the UIComponent with AS too, I just used MXML to get my example up and running quickly.
Any other ideas? Thanks. --- In flexcoders@yahoogroups.com, Sid Maskit <[EMAIL PROTECTED]> wrote: > > There is probably more to it than this, but note that the action script language reference listing for UIComponent says, "The UIComponent class is not used as an MXML tag, but is used as a base class for other classes." > > My suspicion is that it does not contain the logic needed to properly display children that are added to it, and that its descendents provide this logic. > Sid Maskit > Partner > CraftySpace > Better Websites for a Better World > http://www.CraftySpace.com > blog: http://smaskit.blogspot.com/ > > > > ----- Original Message ---- > From: "Merrill, Jason" <[EMAIL PROTECTED]> > To: flexcoders@yahoogroups.com > Sent: Thursday, July 31, 2008 1:18:27 PM > Subject: [flexcoders] problem adding images to UIComponents using AS3 > > > I don't get why this code is failing, it's reproducible if you put an image in the path shown below. (This isn't the actual code in my app, I just isolated a problem and made the problem reproducible it here. In my real app, it's failing to embed an image into a class that is added to a UI component. The class extends Sprite). > The first Image class instance declared with MXML embeds the image just fine. The second, using a UIComponent and adding an instance of the image class to it fails. Why? See comments in the code below: > > <?xml version="1.0"?> > <mx:Application xmlns:mx="http://www.adobe. com/2006/ mxml"> > > <mx:Script> > <![CDATA[ > import mx.controls. Image; > > [Embed(source = "/media/icons/ help.png")] > [Bindable] > private var myHelpImageSource: Class; > > private function initUI():void > { > var myHelpImage: Image = new Image (); > myHelpImage. source = myHelpImageSource; > myUIComponent. addChild( myHelpImage) ; > trace("initUI called.")//traces fine > } > > ]]> > </mx:Script> > > <mx:Panel width="100%" height="100%"> > <mx:Canvas width="600" height="500"> > > <!-- this works to embed the image--> > <mx:Image source="{myHelpImageSource}" x="50" y="50" /> > > <!-- this fails to embed the image using ActionScript above - why? --> > <mx:UIComponent id="myUIComponent" creationComplete="initUI()" x="100" y="100" /> > > </mx:Canvas> > </mx:Panel> > > </mx:Application> > > Jason Merrill > Bank of America > Enterprise Technology & Global Risk L&LD > Instructional Technology & Media > Join the Bank of America Flash Platform Developer Community > Are you a Bank of America associate interested in innovative learning ideas and technologies? > Check out our internal GT&O Innovative Learning Blog & subscribe. >