I didn't read the other replies, but in general I think it's not a good idea to 
add a Flex component to a non-Flex object. You might be able to get it to work 
by simulating the framework workflow - for example, by manually calling all the 
"invalidateXX" methods, however it's not a very clean approach.

In this case, a better way would be to directly create an instance of your 
embedded object and add it to the display list. I think the syntax would be:

var image:BitmapAsset = new _moveGroupImage() as BitmapAsset ; 
this.addChild(image);
            

 --
Laurent Cozic

Flash, Flex and Web Application development
http://pogopixels.com



----- Original Message ----
From: "Merrill, Jason" <[EMAIL PROTECTED]>
To: flexcoders@yahoogroups.com
Sent: Friday, August 1, 2008 4:57:36 PM
Subject: [flexcoders] Re: problem adding images to UIComponents using AS3


OK, let me back up here.  First, thanks to those who responded.   So I thought 
by isolating my problem with an example (heck, I'm not even using Canvas) it 
would shed light on why this bug is occuring, but it isn't unfortunately, I'm 
more or less confusing the real problem with y'all. Sorry.  So maybe what I 
thought was the problem was instead something else.  
Here is my actual project code, and a description of the setup.  The problem 
is, the image is not getting attached to the sprite, even though the sprite is 
showing up in the display list just fine (the graphics draw from code - but the 
image doesn't show).  I know the path to the image is right, I can use the same 
embed and new Image() code elsewhere in my app to make the image appear.  Here 
is the code and the setup in the application:
package com.venice.view. network.grouping Tool  
{ 
        import flash.display. Sprite; 
        import mx.controls. Image; 
        
        public class GroupHandle extends Sprite 
        { 
                public var id:int; 
                
                public const FILL_COLOR:uint = 0xffffff; 
                public const FILL_ALPHA:Number = .5; 
                public const STROKE_COLOR: uint = 0x000000; 
                public const STROKE_THICKNESS: Number = 1; 
                public const STROKE_ALPHA: Number = 1.0; 
                public const SIZE:Number = 10; 
                
                [Embed(source = "/media/icons/ control_repeat_ blue.png")] 
                [Bindable] 
                private var _moveGroupImage: Class; 
                
                public function GroupHandle( ):void 
                { 
                        //this works: 
                        graphics.clear( ); 
                        graphics.lineStyle( STROKE_THICKNESS , STROKE_COLOR, 
STROKE_ALPHA) ; 
                        graphics.beginFill( FILL_COLOR, FILL_ALPHA); 
                        graphics.drawRect( -(SIZE/2) , -(SIZE/2), SIZE/2, 
SIZE/2); 
                        graphics.endFill( ); 
                        
                        //this doesn't: 
                        var icon:Image = new Image(); 
                        icon.source = _moveGroupImage; 
                        addChild(icon) ; 
                } 
        } 
} 
This class, GroupHandle. as, which extends Sprite, is added in the display list 
in my application as follows: 
Application(main MXML)  > network(Panel based MXML component)  >groupsLayerUI 
(a UIComponent, necessary because it's added to a Panel container) 
>groupingTool(.as class that extends Sprite) >groupHandle(.as class that 
extends Sprite)
The groupsLayerUI UIComponent seems to be fine holding other content, and even 
in the groupHandle, it renders drawn graphics just fine. Just not the image. 
Even if I size the UIComponent, it doesn't work.  It's not making any sense to 
me why this image doesn't appear in this sprite, even though it will appear in 
other places in my app, and even though other graphics in the sprite appear 
fine.  I thought maybe it had something to do with also drawing on the same 
sprite, but that's not it either, I removed that code and it still fails to 
load the embedded image.  Can someone figure out what could be wrong?  Thanks.

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. 
    


      

Reply via email to