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  
<blocked::http://sharepoint.bankofamerica.com/sites/tlc/flash/default.aspx> 

Are you a Bank of America associate interested in innovative learning ideas and 
technologies?
Check out our internal  GT&O Innovative Learning Blog 
<blocked::http://sharepoint.bankofamerica.com/sites/ddc/rd/blog/default.aspx>  
& subscribe 
<blocked::http://sharepoint.bankofamerica.com/sites/ddc/rd/blog/_layouts/SubNew.aspx?List=\{41BD3FC9-BB07-4763-B3AB-A6C7C99C5B8D\}&Source=http://sharepoint.bankofamerica.com/sites/ddc/rd/blog/Lists/Posts/Archive.aspx>
 . 


Reply via email to