2013-09-22 93 views
0

我是新来flex.i试图添加图像动态flex使用文件referencei需要添加图像在scroller.i使用下面的代码,但添加图像不可见。任何人都可以帮我关于这个提前动态添加图像到滚动条

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" 
       xmlns:net="flash.net.*"> 
    <fx:Script> 
     <![CDATA[ 
      import mx.controls.Alert; 
      import mx.controls.Image; 
      import mx.utils.ObjectUtil; 
      private var myImage:Image; 
      private function OnbuttonClick(evt:MouseEvent):void { 
       var arr:Array = []; 
       arr.push(new FileFilter("Images", ".gif;*.jpeg;*.jpg;*.png")); 
       fileReference.browse(arr); 
      } 

      private function FileRefSelect(evt:Event):void { 
       fileReference.load(); 
      } 

      private function FileRefComplete(evt:Event):void { 
       Alert.show(ObjectUtil.toString(fileReference)); 
       myImage    = new Image(); 
       //img.source = fileReference.data; 

       myImage.maxWidth = 100; 
       myImage.maxHeight = 100; 
       myImage.source  = fileReference.data; 
       vg.addChild(myImage); 

      } 
     ]]> 
    </fx:Script> 

    <fx:Declarations> 
     <net:FileReference id="fileReference" 
          select="FileRefSelect(event);" 
          complete="FileRefComplete(event);" /> 
    </fx:Declarations> 



    <mx:ControlBar> 
     <mx:Button id="btn" label="Browse Your Image" click="OnbuttonClick(event);" /> 
    </mx:ControlBar> 

    <s:Scroller id="scrllr" x="50" y="100" width="100" height="280" focusEnabled="false" 
       hasFocusableChildren="true"> 
     <s:VGroup id="vg"> 

     </s:VGroup> 
    </s:Scroller> 


</s:Application> 

回答

1

问题pls.Thanks您需要使用vg.addElement(myImage);而不是vg.addChild(myImage);。我假设你也会得到一个相同的例外。