3 Replies Latest reply on Sep 7, 2009 11:39 AM by TheFlexGuy

    Images and AS3

    PrinceKheldar Level 1

      Hello everybody!

      I'm trying to code a very simple Flex application for the browser, to test images. I have included several images in my project. The goal is to have an image that is switched back and forth when clicking on buttons. Seems simple enough.

      But of course I uncountered problems.

      Debug mode helped me understand the reason: I use myImage.source = "nameOfClassImage" when it requires "nameOfClassInstance" in the form ProjetName_NameOfClassImage(someNumberThatSeemsrandomToMe). What do I do wrong (or, put otherwise, how should I do?).

       

       



      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#BA24BC, #EE1111]">
          <mx:Script>
              <![CDATA[
             
                  [Embed(source="../assets/tigre.jpg")]
                  [Bindable]
                  public var TigreImage:Class;
                 
                  [Embed(source="../assets/pyramide.jpg")]
                  [Bindable]
                  public var PyramideImage:Class;
                 
                  [Embed(source="../assets/fondmontagne.jpg")]
                  [Bindable]
                  public var FondMontagneImage:Class;
                 
                  private var textes:Array =new Array("La montagne qu'elle est paisible","Le tigre qui déchire","La pyramide qu'elle est en pierre");
                  private var images:Array =new Array("{FondMontagneImage}","{TigreImage}","{PyramideImage}");
                  private var i:int=0;
                  public function next():void{
                      i++;
                      description_texte.text=textes[i%textes.length]+" : "+ images[i%textes.length];
                      // le probleme: on devrait passer la VALEUR et non le NOM de la "classe" image voulue
                      imageAffichee.source=images[i%textes.length] ;//as Bitmap;
                  }
                  public function previous():void{
                      if (i>0)
                      i--;
                      description_texte.text=textes[i%textes.length]+" : "+ images[i%textes.length];
                      imageAffichee.source=images[i%textes.length] ;//as Bitmap;
                  }
              ]]>
          </mx:Script>
          <mx:Image x="298" y="47" width="145" height="157" scaleContent="true" id="imageAffichee" source="{TigreImage}"/>
          <mx:Button x="298" y="212" label="Reculer" id="reculer_bouton" click="previous()"/>
          <mx:Text  x="451" y="47" text="Cette vieille femme garde des chèvres (biquettes! biquettes!) tout près de Saqqara." height="187" width="246" id="description_texte"/>
          <mx:Button x="369" y="212" label="Avancer" id="avancer_bouton" click="next()"/>
          <mx:Label x="75" y="47" text="Egypte 2008" color="#E2D113" fontWeight="bold" fontFamily="Arial" fontSize="20" fontStyle="normal" textDecoration="normal" id="titre_dossier"/>
         
      </mx:Application>