我在Flex 3中使用AS3来创建新图像,似乎无法获得原始图像的确切大小.percentHeight和percentWidth到100可以完成这项工作,但是ObjectHandlers中的限制要求我以像素为单位设置图像比例.
有解决方案吗
注意:这也适用于显示没有ObjectHandler控件的图像原始尺寸,只需删除那些不适用的行.
经过努力解决问题的时间后,我通过动作论坛找到了我自己的答案,事实上,只有一个解决方案,我很惊讶其他地方没有这样的话题.
private function init():void { var image:Image = new Image(); image.source = "http://www.colorjack.com/software/media/circle.png"; image.addEventListener(Event.COMPLETE, imageLoaded); /* wait for completion as Image control is asynchronous, * which mean ObjectHandler will attempt to load asap * and you are not able to get the correct dimension for scaling. * EventListener fixed that. */ this.addChild(image); //whenever you scale ObjectHandler control, the image is always fit by 100% image.percentHeight = 100; image.percentWidth = 100; } private function imageLoaded(e:Event):void{ var img:Image = e.target as Image; trace("Height ", img.contentHeight); trace("Width ", img.contentWidth); var oh:ObjectHandles = new ObjectHandles(); oh.x = 200; oh.y = 200; oh.height = img.contentHeight; oh.width = img.contentWidth; oh.allowRotate = true; oh.autoBringForward = true; oh.addChild(img); genericExamples.addChild(oh); }