RE: [flexcoders] problem adding images to UIComponents using AS3
Thanks Alex, Loader (finally) got the job done. I was hoping for a more direct solution, but this should work. --Steve >One of my responses to the thread said that you probably can't wrap >UIComponents in non-UIComponents. You'll have to use >flash.display.Loader instead of mx:Image or just use UIComponent instead >of MovieClip. I don't think there's much savings -- View this message in context: http://www.nabble.com/problem-adding-images-to-UIComponents-using-AS3-tp18762698p18826107.html Sent from the FlexCoders mailing list archive at Nabble.com.
RE: [flexcoders] problem adding images to UIComponents using AS3
One of my responses to the thread said that you probably can't wrap UIComponents in non-UIComponents. You'll have to use flash.display.Loader instead of mx:Image or just use UIComponent instead of MovieClip. I don't think there's much savings From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of scole Sent: Monday, August 04, 2008 7:02 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] problem adding images to UIComponents using AS3 Hi, I've been following this thread with interest since I was having the exact same problem as Jason. Instead of a Sprite, though, I'd like to be able to load an image into a MovieClip, which would then be loaded into a UIComponent so it can be displayed inside a Panel. I suspect it shouldn't be much different than using a Sprite, since MovieClip extends Sprite. Here's the relevant mxml: Now, MyMovieClip is a custom class extending MovieClip: package myComponents { import flash.display.MovieClip; import mx.core.UIComponent; import mx.controls.Image; public class MyMovieClip extends MovieClip { public function MyMovieClip() { super(); var image1:Image = new Image(); image1.source = "../pics/batman.jpg"; image1.setActualSize(100,100); this.addChild(image1); this.scaleX=1.0; this.scaleY=1.0; this.height = 100; this.width = 100; //just to see if I can set any properties this.x = 2; this.y = 2; graphics.beginFill(0x00); graphics.drawRect(20,20,50,50); graphics.endFill(); //prints 0, as expected trace("ChildIndex of image in MyMovieClip:"+this.getChildIndex(image1).toString()); } } } When I put breakpoints in here, the 'x' and 'y' properties are appropriately changed to 2, and the graphics display just fine, but 'height' and 'width' both remain at 0, even after the statements to set them. The DisplayObjectWrapper class is a custom extension of UIComponent that I found on another forum which is specifically designed to assist in adding DisplayObjects to UIComponents. (http://www.gskinner.com/blog/archives/2007/03/displayobjectwr.html <http://www.gskinner.com/blog/archives/2007/03/displayobjectwr.html> ) As per Amy's post, >Second, you need to explicitly give it a size. I think the >conventional method for doing this is to call setActualSize() on the >child image. I think the conventional place to do this is >updateDisplayList(), though I'm no whiz kid and I could be wrong. I checked to see that DisplayObjectWrapper had measure() and updateDisplayList() methods; it did not have an updateDisplayList() method, so I cobbled one up. It's a little ugly, because the children of this DisplayObjectWrapper will be MovieClips, and so I can't call the setActualSize() method on them; instead, just to see if I could get it working, I explicitly set the height and width to be the same of the parent DisplayObjectWrapper: override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { super.updateDisplayList(unscaledWidth, unscaledHeight); //set actual size of all children for (var i:int = 0; i < numChildren; i++) { //set width and height of every child to that of the full UIComponent DisplayObject(getChildAt(i)).width=unscaledWidth; DisplayObject(getChildAt(i)).height=unscaledHeight; } } So, the graphics in the MovieClip display correctly, and the image displays with no problem when loaded directly into the Panel, but it still seems that the MovieClip is of size 0 and of course no Image can be seen inside it. Any insight would be much appreciated. --Steve -- View this message in context: http://www.nabble.com/problem-adding-images-to-UIComponents-using-AS3-tp 18762698p18805059.html <http://www.nabble.com/problem-adding-images-to-UIComponents-using-AS3-t p18762698p18805059.html> Sent from the FlexCoders mailing list archive at Nabble.com.
Re: [flexcoders] problem adding images to UIComponents using AS3
Hi, I've been following this thread with interest since I was having the exact same problem as Jason. Instead of a Sprite, though, I'd like to be able to load an image into a MovieClip, which would then be loaded into a UIComponent so it can be displayed inside a Panel. I suspect it shouldn't be much different than using a Sprite, since MovieClip extends Sprite. Here's the relevant mxml: Now, MyMovieClip is a custom class extending MovieClip: package myComponents { import flash.display.MovieClip; import mx.core.UIComponent; import mx.controls.Image; public class MyMovieClip extends MovieClip { public function MyMovieClip() { super(); var image1:Image = new Image(); image1.source = "../pics/batman.jpg"; image1.setActualSize(100,100); this.addChild(image1); this.scaleX=1.0; this.scaleY=1.0; this.height = 100; this.width = 100; //just to see if I can set any properties this.x = 2; this.y = 2; graphics.beginFill(0x00); graphics.drawRect(20,20,50,50); graphics.endFill(); //prints 0, as expected trace("ChildIndex of image in MyMovieClip:"+this.getChildIndex(image1).toString()); } } } When I put breakpoints in here, the 'x' and 'y' properties are appropriately changed to 2, and the graphics display just fine, but 'height' and 'width' both remain at 0, even after the statements to set them. The DisplayObjectWrapper class is a custom extension of UIComponent that I found on another forum which is specifically designed to assist in adding DisplayObjects to UIComponents. (http://www.gskinner.com/blog/archives/2007/03/displayobjectwr.html) As per Amy's post, >Second, you need to explicitly give it a size. I think the >conventional method for doing this is to call setActualSize() on the >child image. I think the conventional place to do this is >updateDisplayList(), though I'm no whiz kid and I could be wrong. I checked to see that DisplayObjectWrapper had measure() and updateDisplayList() methods; it did not have an updateDisplayList() method, so I cobbled one up. It's a little ugly, because the children of this DisplayObjectWrapper will be MovieClips, and so I can't call the setActualSize() method on them; instead, just to see if I could get it working, I explicitly set the height and width to be the same of the parent DisplayObjectWrapper: override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { super.updateDisplayList(unscaledWidth, unscaledHeight); //set actual size of all children for (var i:int = 0; i < numChildren; i++) { //set width and height of every child to that of the full UIComponent DisplayObject(getChildAt(i)).width=unscaledWidth; DisplayObject(getChildAt(i)).height=unscaledHeight; } } So, the graphics in the MovieClip display correctly, and the image displays with no problem when loaded directly into the Panel, but it still seems that the MovieClip is of size 0 and of course no Image can be seen inside it. Any insight would be much appreciated. --Steve -- View this message in context: http://www.nabble.com/problem-adding-images-to-UIComponents-using-AS3-tp18762698p18805059.html Sent from the FlexCoders mailing list archive at Nabble.com.
RE: [flexcoders] problem adding images to UIComponents using AS3
Parents size their children in Flex, so the UIComponent's image size is probably zero since nobody sized it From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Sid Maskit Sent: Thursday, July 31, 2008 1:39 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] problem adding images to UIComponents using AS3 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: http://www.adobe. com/2006/ mxml <http://www.adobe.com/2006/mxml> "> 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.
Re: [flexcoders] problem adding images to UIComponents using AS3
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: http://www.adobe. com/2006/ mxml"> 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.
[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: http://www.adobe.com/2006/mxml";> Jason Merrill Bank of America Enterprise Technology & Global Risk L&LD Instructional Technology & Media Join the Bank of America Flash Platform Developer Community 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 http://sharepoint.bankofamerica.com/sites/ddc/rd/blog/default.aspx> & subscribe 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> .