2010-04-14 16 views
0

我正在嘗試使用ActionScript爲圖像添加鏈接。無論如何,我都看不到鏈接。下面是我的代碼,你能提出建議我做錯了什麼。我正在嘗試在圖像上添加鏈接

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application creationComplete="application1_creationCompleteHandler(event)" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600"> 
    <mx:Script> 
     <![CDATA[ 
      import mx.controls.Button; 
      import mx.controls.Image; 
      import mx.events.FlexEvent; 

      protected function application1_creationCompleteHandler(event:FlexEvent):void 
      {    
       var but:Button = new Button(); 
       but.label = "BUT"; 
       uic.addChild(but); 
         var dollLoader:Loader=new Loader(); 
           dollLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, dollCompleteHandler); 
           var dollRequest:URLRequest = new URLRequest("http://www.google.com/intl/en_ALL/images/logo.gif"); 
           dollLoader.load(dollRequest); 
           uic.addChild(dollLoader); 

       } 

      private function dollCompleteHandler(event:Event):void 
         { 


         } 

     ]]> 
    </mx:Script> 

    <mx:UIComponent id="uic" width="100%" height="100%"> 

    </mx:UIComponent> 

</mx:Application> 

回答

1

兩個建議:

  1. 按鈕被掩蓋了的形象,因爲你要添加的順序的。在圖像之後而不是之前添加按鈕。

  2. 除非指定高度&寬度,否則將無法看到該按鈕。

例:

but.width = 100; 
but.height = 100; 
+0

嘗試設置dollLoader'的'尺寸太大。使用'UIComponent'作爲父容器可以給出意想不到的結果。如果將'UIComponent'更改爲'Canvas'或'VBox',會發生什麼? – 2010-04-15 21:13:13

+0

只需設置寬度和高度....解決了問題。 but.width = 100; but.height = 100; 謝謝 – firemonkey 2010-04-15 22:27:33