Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 Flex 4-如何将图像数据存储到变量或对象中_Actionscript 3_Apache Flex_Flex4 - Fatal编程技术网

Actionscript 3 Flex 4-如何将图像数据存储到变量或对象中

Actionscript 3 Flex 4-如何将图像数据存储到变量或对象中,actionscript-3,apache-flex,flex4,Actionscript 3,Apache Flex,Flex4,我的编码 <fx:Script> <![CDATA[ private var loadFile:FileReference; protected function browseButtonClickHandler(event:MouseEvent):void { loadFile = new FileReference(); loadFile.addEventList

我的编码

    <fx:Script>
    <![CDATA[
        private var loadFile:FileReference;
        protected function browseButtonClickHandler(event:MouseEvent):void
        {
            loadFile = new FileReference();
            loadFile.addEventListener(Event.SELECT, fileSelectHandler);
            var fileFilter:FileFilter = new FileFilter("Images: (*.jpeg, *.jpg, *.gif, *.png)", "*.jpeg; *.jpg; *.gif; *.png");
            loadFile.browse([fileFilter]);
        }

        protected function fileSelectHandler(event:Event):void
        {
            loadFile.load();
            urlInput.text = event.target.name;
        }
        public function addButtonClickEvent(event:MouseEvent):void
        {
            if (urlInput.text.length == 0)
            {
                var num:int = gender.selectedIndex;
                var img:ByteArray = new ByteArray();
                var url:URLRequest = new URLRequest("http://localhost/demo/images/image.jpg");
                var loader:Loader = new Loader();
                loader.load(url);
                if (num == 0)
                {

                    urlInput.text = "male.jpg";
                    img = url.data; 
                }
            } 
            else
            {
                img = loadFile.data;
            }
            empDetails.addItem({
                name : nameInput.text,
                image : img
            });
        }

    ]]>
</fx:Script>
<s:Form id="addForm">
    <s:FormItem id="nameLabel" label="Name">
        <s:TextInput  id="nameInput"/>
    </s:FormItem>
    <s:FormItem id="urlLabel" label="Employee Image:">
        <s:HGroup>
            <s:TextInput id="urlInput" editable="false"/>
            <s:Button id="browseButton" label="Browse" click="browseButtonClickHandler(event)"/>
        </s:HGroup>
    </s:FormItem>
    <s:FormItem>
        <s:HGroup>
            <s:Button id="addButton" label="Add" click="addButtonClickEvent(event)"/>
        </s:HGroup>
    </s:FormItem>
</s:Form>

在这里,我必须将名称和图像添加到ArrayCollection中以备将来使用。如果我没有在这里选择image,它将抛出一个异常。但我需要的是,若我并没有在表单中选择图像,那个么它必须将这个图像“image.jpg”作为一个选择的图像。但这里有一个错误,就像 此行有多个标记: -1118:将具有静态类型对象的值隐式强制到可能不相关的类型flash.utils:ByteArray。 -img
我不知道如何删除这个错误。如果有人能找到它,请通知我?或者如何执行此任务?

该错误来自img=url.data或img.loadFile.data。您需要将数据强制转换为ByteArray。您可以进一步解释或共享将数据强制转换为ByteArray的代码吗