here is a little sample code of loading an image from the web then scaling it and using it as a buttons icon. You should be able to easily modify this to work with embedded assets. If not let me know and I could spend a little time later doing that also.
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*" x="100" y="121"> <mx:Script> <![CDATA[ import mx.controls.Button; import mx.controls.Image; import mx.core.MovieClipAsset; import mx.events.FlexEvent; private var loader:Loader; private var request:URLRequest; private function setIcon(target:Button, url:String):void { var iconLoader:Loader = new Loader(); //Set the complete handler to use a decorated function based on the iconName iconLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, iconLoaderCompleteDecorator(target)); iconLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, iconIOErrorHandler); iconLoader.load(new URLRequest(url)); } private function iconLoaderCompleteDecorator(target:Button):Function { //Build the real function that will handle the events var realHandler:Function = function bla(event:Event):void { var loadedIcon:DisplayObject = LoaderInfo(event.target).content replaceIcon(target, "upIcon", new Bitmap(Bitmap(loadedIcon).bitmapData, "auto", true)); replaceIcon(target, "downIcon", new Bitmap(Bitmap(loadedIcon).bitmapData, "auto", true)); replaceIcon(target, "overIcon", new Bitmap(Bitmap(loadedIcon).bitmapData, "auto", true)); }; return realHandler; } private function replaceIcon(target:Button, iconName:String, newIcon:DisplayObject):void { trace("loaded"); var iconToReplace:DisplayObject = target.getChildByName(iconName); trace(iconToReplace); if (iconToReplace) { target.removeChild(iconToReplace); } iconToReplace = null; //use a movie clip asset to support both images and swfs //this also allows us to add children to the icon if we want //because MovieClipAsset is a DisplayObjectContainer iconToReplace = new MovieClipAsset(); iconToReplace.name = iconName; iconToReplace.visible = false; target.addChild(iconToReplace); var maxIconWidth:Number = 25; var maxIconHeight:Number = 25; if (newIcon.width > maxIconWidth || newIcon.height > maxIconHeight) { var scaleX:Number = maxIconWidth / newIcon.width; var scaleY:Number = maxIconHeight / newIcon.height; if (isNaN(scaleX)) scaleX = 1; if (isNaN(scaleY)) scaleY = 1; var maxScale:Number = Math.min(scaleX, scaleY); if (maxScale != 1) { var trans:Matrix = new Matrix(); trans.scale(maxScale, maxScale); newIcon.transform.matrix = trans; } } //Now that we are all clear add the real icon on top of the MovieClipAsset(iconToReplace).addChild(newIcon); //Add a transparent layer to for the icon size incase the swf //changes sizes while playing MovieClipAsset(iconToReplace).addChild(new Bitmap(new BitmapData(newIcon.width, newIcon.height, true, 0x00FFFFFF))); target.invalidateDisplayList(); target.invalidateProperties(); target.invalidateSize(); } private function iconIOErrorHandler(event:IOErrorEvent):void { trace("fail"); } ]]> </mx:Script> <mx:LinkButton id="button1" label="Click here to use the image below as an icon for this button" x="10" y="10" click="setIcon(button1, 'http://www.spacetoday.org/images/SolSys/Earth/EarthBlueMarbleWestTerra.jpg')"/> <mx:Image source="http://www.spacetoday.org/images/SolSys/Earth/EarthBlueMarbleWestTerra.jpg" x="10" y="40"/> <mx:LinkButton id="button2" label="try me" x="342" y="40" click="setIcon(button2, 'http://bioweb.uwlax.edu/bio203/s2008/kwong_hoi/images/Adorable-Cats-Screensaver.jpg')"/> <mx:LinkButton id="button3" label="and me" x="342" y="70" click="setIcon(button3, 'http://onflex.org/images/Fx.png')"/> </mx:Application> --- In flexcoders@yahoogroups.com, "grg_blls" <grg_b...@...> wrote: > > Hi, > > Downscaling of a bitmap image can be done in a number of ways (downsampling > is a better term and procedure). > > The real problem is: what do you expect the outcome to be, if you scale down > a line graphic of 1 pixel width, or a detail in the bitmap of 1 pixel in the > original 50x50 bitmap that has to be scaled to 15x15 pixels, i.e. 330% down! > (this is the original question). > One third of a pixel? > > Do it any way you like it, but the result has to be 1/3 of a pixel whatever > that means and however this appears ... :) > > thanks > George > > > --- In flexcoders@yahoogroups.com, "flexaustin" <flexaustin@> wrote: > > > > Yes, code would be great! I can't believe how difficult this is to get > > implemented. Hope these things become easier in Flex 5. > > > > J > > > > --- In flexcoders@yahoogroups.com, "ag_rcuren" <robert.vancuren.jr@> wrote: > > > > > > I ran into this same problem and could not find and easy fix. I ended up > > > extending the LinkButton class. I created a button class that can load > > > it's icons on the fly from any where local, net, or embedded. Instead of > > > needing to set them strictly to Class I created a iconSource property. > > > This allowed me to load the image scale it down and then use that scaled > > > image as the icon. This required some trickery as you have to get the > > > icon for each state by name and manually add your custom icons, but it > > > does work just fine. I don't have time to include code right now but I > > > can post some example code later if you would like. I hope what I said > > > made sense. > > > > > > > > > --- In flexcoders@yahoogroups.com, "flexaustin" <flexaustin@> wrote: > > > > > > > > I am trying to use a LinkButton in my app and assign an image to the > > > > icon variable, but I need to scale down or make sure the image isn't > > > > any larger than 15 x 15 pixels. > > > > > > > > Is there a way to scale a class file? I tried to load a png file then > > > > convert the png to Bitmap, tried BitmapData, and tried BitmapAsset and > > > > then scale the embedded image, but non of this worked. > > > > > > > > So to recap embed and image (which is 50x50 pixels) and shrink it down > > > > to (15x15 pixels) and assign it to a linkButtons icon. > > > > > > > > Anyone know of a solution? > > > > > > > > > >