10 Replies Latest reply on Jul 23, 2011 11:45 AM by lingo55

    Help loading an image file

    lingo55 Level 1

      Hi, I have an image on my movie that I am now able to move around and resize. What I want now is to replae this image with a different one (ie. user's own logo) by displaying a file browser window when user clicks on the current image.

       

      My actual image is "your_logo.png". Please bear in mind I am VERY new to Flash Builder. Here´s my code:

       

      <?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"

      width="

      874" height="700">

       

       

       

      <fx:Script>

      <![CDATA[

       

      import mx.controls.Alert;

       

      import mx.events.FlexEvent;

       

      import mx.managers.CursorManager;

       

        

       

      [

      Bindable]

      [

      Embed(source="images/moveCursor.png")]

       

      private var myCursorIcon:Class;

       

      protected function clickHandler(event:MouseEvent):void

      {

       

      CursorManager.setCursor(myCursorIcon);

      }

       

       

      protected function resetHandler(event:MouseEvent):void

      {

       

      CursorManager.removeAllCursors();

      }

       

       

      // esta función hace que al reducir y ampliar imágenes, estas no se distorsionen

       

       

      private function smoothImage(evt:Event):void{

       

      var myBitmap:Bitmap = ((evt.target as Image).content as Bitmap);

       

      if (myBitmap != null) {

      myBitmap.smoothing =

      true;

      }

      }

       

       

      // esta función hace que podamos manipular el tamaño del texto con un slider. Una para cada texto.

       

      protected function resizeMyName_changeHandler(event:Event):void

      {

       

      // TODO Auto-generated method stub

      MyName.textFlow.fontSize = resizeMyName.value;

      }

       

       

      protected function resizeMyAddress_changeHandler(event:Event):void

      {

       

      // TODO Auto-generated method stub

      MyAddress.textFlow.fontSize = resizeMyAddress.value;

      }

       

      protected function resizeMyPhone_changeHandler(event:Event):void

      {

       

      // TODO Auto-generated method stub

      MyPhone.textFlow.fontSize = resizeMyPhone.value;

      }

       

      protected function resizeMyFax_changeHandler(event:Event):void

      {

       

      // TODO Auto-generated method stub

      MyFax.textFlow.fontSize = resizeMyFax.value;

      }

       

      protected function resizeMyMobile_changeHandler(event:Event):void

      {

       

      // TODO Auto-generated method stub

      MyMobile.textFlow.fontSize = resizeMyMobile.value;

      }

       

      protected function resizeMyEmail_changeHandler(event:Event):void

      {

       

      // TODO Auto-generated method stub

      MyEmail.textFlow.fontSize = resizeMyEmail.value;

      }

       

      protected function resizeMyWebsite_changeHandler(event:Event):void

      {

       

      // TODO Auto-generated method stub

      MyWebsite.textFlow.fontSize = resizeMyWebsite.value;

      }

       

       

       

       

      ]]>

       

       

      </fx:Script>

       

       

       

       

      <s:BorderContainer x="10" y="10" width="853" height="680" backgroundColor="#F0EEEE">

       

       

      <s:BorderContainer

       

       

      width="

      630"

      height="

      394"

      x="

      33" y="170"

      borderVisible="

      true"

      dropShadowVisible="

      true" borderColor="#E1E1E1">

       

       

       

      <s:layout>

       

      <s:BasicLayout/>

       

      </s:layout>

       

       

      <s:RichEditableText

      id="

      MyAddress"

      text="

      my address here"

      fontSize="

      12"

      mouseDown="MyAddress.startDrag();"

      mouseUp="MyAddress.stopDrag();"

      mouseOut="resetHandler(event)"

      mouseOver="clickHandler(event)"

      x="

      114" y="64" fontFamily="Verdana" textAlign="right"

       

      />

       

       

      <s:RichEditableText

      id="

      MyWebsite"

      text="

      my website here"

      fontSize="

      12"

      mouseDown="MyWebsite.startDrag();"

      mouseUp="MyWebsite.stopDrag();"

      mouseOut="resetHandler(event)"

      mouseOver="clickHandler(event)"

      x="

      115" y="158" fontFamily="Verdana" textAlign="right"/>

       

       

      <s:RichEditableText

      id="

      MyPhone"

      text="

      my phone here"

      fontSize="

      12"

      mouseDown="MyPhone.startDrag();"

      mouseUp="MyPhone.stopDrag();"

      mouseOut="resetHandler(event)"

      mouseOver="clickHandler(event)"

      x="

      125" y="82" fontFamily="Verdana" textAlign="right"/>

       

      <s:RichEditableText

      id="

      MyFax"

      text="

      my fax here"

      fontSize="

      12"

      mouseDown="MyFax.startDrag();"

      mouseUp="MyFax.stopDrag();"

      mouseOut="resetHandler(event)"

      mouseOver="clickHandler(event)"

      x="

      146" y="99" fontFamily="Verdana" textAlign="right"/>

       

      <s:RichEditableText

      id="

      MyMobile"

      text="

      my mobile here"

      fontSize="

      12"

      mouseDown="MyMobile.startDrag();"

      mouseUp="MyMobile.stopDrag();"

      mouseOut="resetHandler(event)"

      mouseOver="clickHandler(event)"

      x="

      124" y="116" fontFamily="Verdana" textAlign="right"/>

       

      <s:RichEditableText

      id="

      MyEmail"

      text="

      my email here"

      fontSize="

      12"

      mouseDown="MyEmail.startDrag();"

      mouseUp="MyEmail.stopDrag();"

      mouseOut="resetHandler(event)"

      mouseOver="clickHandler(event)"

      x="

      132" y="133" fontFamily="Verdana" textAlign="right"/>

       

      <s:RichEditableText

      id="

      MyName"

      text="

      my name here"

      fontSize="

      24"

      mouseDown="MyName.startDrag();"

      mouseUp="MyName.stopDrag();"

      mouseOut="resetHandler(event)"

      mouseOver="clickHandler(event)"

      x="

      50" y="23" fontFamily="Verdana" textAlign="right"

       

      />

       

       

      <mx:Image x="289"

      y="

      289"

      source="

      images/your_logo.png"

      mouseDown="img1.startDrag();"

      mouseUp="img1.stopDrag();"

      mouseOut="resetHandler(event)"

      mouseOver="clickHandler(event)"

      id="

      img1"

      complete="smoothImage(event)"

      />

       

      </s:BorderContainer>

       

       

      <s:BorderContainer x="11" y="10" width="830" height="114" borderVisible="true" cornerRadius="20" borderColor="#D4D4D4">

       

      <mx:Image x="20"

      y="

      7"

      source="

      images/logo_construction.png"

       

      />

       

      </s:BorderContainer>

       

       

      <s:HSlider

      x="

      711"

      y="

      235"

      minimum="

      100"

      maximum="

      350"

      change="img1.width=event.currentTarget.value"

      liveDragging="

      true"

      value="

      350" stepSize="10" id="resizeLogo"/>

       

       

      <s:Label x="711"

      y="

      190"

      text="

      RESIZE"

      fontWeight="

      bold"

      fontFamily="

      Verdana"

      fontSize="

      10"/>

       

      <s:Label x="712"

      y="

      252"

      text="

      my name"

      fontWeight="

      normal"

      fontFamily="

      Verdana"

      fontSize="

      10"/>

       

      <s:Label x="712"

      y="

      222"

      text="

      logo"

      fontWeight="

      normal"

      fontFamily="

      Verdana"

      fontSize="

      10"/>

       

      <s:HSlider

      x="

      711"

      y="

      264"

      value="

      24"

      stepSize="

      2"

      maximum="

      24"

      minimum="

      14"

      id="

      resizeMyName"

      liveDragging="

      true"

      change="resizeMyName_changeHandler(event)"

       

      />

       

      <s:HSlider

      x="

      712"

      y="

      296.15"

      value="

      12"

      stepSize="

      1"

      maximum="

      18"

      minimum="

      12"

      id="

      resizeMyAddress"

      change="resizeMyAddress_changeHandler(event)"

       

      />

       

      <s:HSlider

      x="

      712"

      y="

      324"

      value="

      12"

      stepSize="

      1"

      maximum="

      18"

      minimum="

      12"

      id="

      resizeMyPhone"

      change="resizeMyPhone_changeHandler(event)"

       

      />

       

      <s:HSlider

      x="

      712"

      y="

      353"

      value="

      12"

      stepSize="

      1"

      maximum="

      18"

      minimum="

      12"

      id="

      resizeMyFax"

      change="resizeMyFax_changeHandler(event)"

       

      />

       

      <s:HSlider

      x="

      712"

      y="

      380"

      value="

      12"

      stepSize="

      1"

      maximum="

      18"

      minimum="

      12"

      id="

      resizeMyMobile"

      change="resizeMyMobile_changeHandler(event)"

       

      />

       

      <s:HSlider

      x="

      712"

      y="

      406"

      value="

      12"

      stepSize="

      1"

      maximum="

      18"

      minimum="

      12"

      id="

      resizeMyEmail"

      change="resizeMyEmail_changeHandler(event)"

       

      />

       

      <s:HSlider

      x="

      712"

      y="

      432"

      value="

      12"

      stepSize="

      1"

      maximum="

      18"

      minimum="

      12"

      id="

      resizeMyWebsite"

      change="resizeMyWebsite_changeHandler(event)"

       

      />

       

      <s:Label x="712.5"

      y="

      284.15"

      text="

      my address"

      fontWeight="

      normal"

      fontFamily="

      Verdana"

      fontSize="

      10"/>

       

      </s:BorderContainer>

      </s:Application>