3 Replies Latest reply on Aug 13, 2009 7:25 AM by Gregory Lafrance

    Problem with Showing Images in <Canvas>

    hacmac

      I have now tried for hours and I'm a step nearer to the Solution I think but my Problem are continueing.

       

      I try to show a picture in one MXML and send the URL from another MXML on Buttonclick . I'll post the Code for better understanding.

       

      If I'll put all in one File it works, when splitting, the Browser says it loads the image, but nothing is happening.

       

      Does anyone have a Solution for this Problem? Putting all together in one file is not fitting my Expectations!


      [Code = Flexbildtest.mxml]

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application
          xmlns:mx="http://www.adobe.com/2006/mxml"
          xmlns:cust="CustomComponents.*"
          layout="absolute">
         
          <cust:Clicker height="50%" width="50%"/>
          <cust:Shower height="50%" width="50%" y="234"/>
         
      </mx:Application>

      [/Code]

       

      [Code= Clicker.mxml]

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
          <mx:Script>
              <![CDATA[
                  import mx.controls.Image;
                  import CustomComponents.*;
                 
                  private function buttonClick(event:Event):void{
                 
                   
                    var shower:Shower = new Shower();
                   
                        shower.getBild("http://www.whatever.com/please_insert_your_own.jpg");
                 
                  }
                 
              ]]>
          </mx:Script>
         
          <mx:Button x="10" y="10" label="Load" id="but" click="buttonClick(event)"/>
      </mx:Canvas>

      [/Code]

       

      [Code= Shower.mxml]

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
          <mx:Script>
              <![CDATA[
                  import mx.controls.Image;
                 
                  public function getBild(url:String):void {
                 
                      var img:Image = new Image();
                 
                      img.load(url);
                      img.x = 50;
                      img.y = 50;
                      addChild(img);
                     
                 
                  }
              ]]>
          </mx:Script>
          <mx:Label x="10" y="10" text="Hallo"/>

      </mx:Canvas>

      [/Code]