FLEX未显示图像

时间:2013-09-18 19:01:47

标签: image flex

Flex没有显示图片我已尝试过许多网页,可以帮助任何人帮助我

  <?xml version="1.0"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
        <mx:Script><![CDATA[
            public var photo:FileReference = new FileReference();

            protected function crop_clickHandler():void
            {
                var f:FileFilter = new FileFilter("Image", "*.jpg;*.jpeg;*;*.gif;*.png;");
                photo.addEventListener(Event.SELECT, fileSelected);
                photo.browse([f]);
            }

            private function fileSelected(evt:Event):void
            {
                photo.addEventListener(Event.COMPLETE,loadCompleted);
                photo.load();
            }

            private var loader : Loader = new Loader();

            private function loadCompleted(evt:Event):void
            {
                loader.contentLoaderInfo.addEventListener(Event.COMPLETE, getBitmapData);
                loader.loadBytes(photo.data);

            }

            private function getBitmapData(event:Event):void
            {
                var content:DisplayObject = loader.content;
                var BMPData:BitmapData = new BitmapData(content.width,content.height);

                //  var imgObj:Object = new Object();
                var bmd:BitmapData;
                bmd = Bitmap(event.currentTarget.content).bitmapData;
                var bmpMy:Bitmap = new Bitmap(bmd);
                myImage1.source=bmpMy
                // myImage1.addChild(DisplayObject(bmpMy));


            }
            ]]></mx:Script>

我甚至试图在加载后在这里显示图像,但它没有像我尝试的那样工作

        <mx:Button id="btnLoad" label="Browse Image" click="crop_clickHandler()" ></mx:Button>
        <mx:Image id="myImage1" x="50" y="50" height="100%" width="100%" maintainAspectRatio="false" autoLoad="true" ></mx:Image>

    </mx:Application>

1 个答案:

答案 0 :(得分:0)

您正在访问FileReference上的方法,这些方法在Flash Player 9中不可用(Flex 3.6的默认设置)。

您需要做的是定位Flash Player 10.1或更高版本。以下是针对11.1的说明,因为这是Flex 4附带的内容。

首先,在项目属性中的“Flex Compiler”下更新目标播放器:

enter image description here

其次,转到Flex Build Path并从Flex 3.6a菜单下删除playerglobal.swc。然后单击Add SWC并为目标播放器版本选择playerglobal.swc(查看FLEX_SDK / frameworks / libs / player / 11.1)。

enter image description here

之后不要忘记做一个Project Clean。

您现在应该能够按原样运行代码。