4 Replies Latest reply on Apr 2, 2007 3:11 PM by justinc9112

    Image Swap

    justinc9112
      Okay I have an application and each time a accordion index gets selected I want the picture source in the box to change to another image depending on which accordion index is selected. Here is an idea of what I was trying to do below, any help would be greatly appreciated. Thank you in advance.

      <mx:Image height="131" width="96" scaleContent="false" autoLoad="true"
      if ="accordion.selectedIndex=0"
      source="Movie Pictures/good-shepherd-06.jpg";
      else if ="accordion.selectedIndex=1"
      source=" Movie Pictures/attack-of-the-gryphon.jpg";
      else if ="accordion.selectedIndex=2"
      source=" Movie Pictures/death-of-a-president.jpg";
      else if ="accordion.selectedIndex=3"
      source=" Movie Pictures/king-maker.jpg";
      else if ="accordion.selectedIndex=4"
      source=" Movie Pictures/charlottes-web.jpg"; />


      Since I am quite new if anyone has any other simpler methods I am all ears. Thanks.
        • 1. Re: Image Swap
          michael_ramirez44 Level 1
          public function changeHandler(event:IndexChangeEvent):void
          {

          if( event.newIndex == 0 )
          {
          myImage.source="Movie Pictures/good-shepherd-06.jpg";
          }
          else if( ... )
          {
          ...
          }

          }

          <mx:Image id="myImage" height="131" width="96" scaleContent="false" autoLoad="true"/>

          <mx:Accordion id="accordion" width="100%" height="100%" change="changeHandler(event)">
          ...
          </mx:Accordion>
          • 2. Re: Image Swap
            justinc9112 Level 1
            thank you worked perfectly
            • 3. Re: Image Swap
              justinc9112 Level 1
              lol had a parse error at accordion start tag.

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
              <mx:Style source="css.css" />

              <mx:Panel layout="absolute" title="Movies For Week of April 3" x="146.5" height="464" y="24" horizontalAlign="center" verticalAlign="middle" width="787">
              public function changeHandler(event:IndexChangeEvent):void
              {

              if( event.newIndex == 0 )
              {
              myImage.source="Movie Pictures/good-shepherd-06.jpg";
              }
              else if( event.newIndex == 1 )
              {
              myImage.source="Movie Pictures/attack-of-the-gryphon.jpg";
              }
              else if( event.newIndex == 2 )
              {
              myImage.source="Movie Pictures/death-of-a-president.jpg";
              }
              else if( event.newIndex == 3 )
              {
              myImage.source="Movie Pictures/king-maker.jpg";
              }
              else if( event.newIndex == 4 )
              {
              myImage.source="Movie Pictures/charlottes-web.jpg";
              }
              }

              <mx:Accordion id="accordion" width="407" height="100%" change="changeHandler(event)" >
              <mx:Canvas label="The Good Shepherd" width="403" height="309">
              <mx:TextArea x="10" y="10" width="382" height="265" fontWeight="bold" borderStyle="none">
              <mx:text><![CDATA[Genre: Thriller

              Description: Based on the acclaimed book by children's author E.B. White, Charlotte's Web is the story of Wilbur the Pig, Charlotte the Spider and all the animals of the farm who help to save Wilbur from an untimely date with the dinner table. A story of true friendship, it has won the hearts of children and adults around the world with its tale of overcoming obstacles and adversity with a little help from the people that matter the most.

              Cast: Julia Roberts, Steve Buscemi, John Cleese, Oprah Winfrey, Cedric the Entertainer, Dakota Fanning, Thomas Haden Church
              ]]></mx:text>
              </mx:TextArea>

              </mx:Canvas>
              <mx:Canvas label="Attack of the Gryphon" width="100%" height="100%">
              <mx:TextArea x="10" y="10" height="265" width="382" fontWeight="bold" borderStyle="none">
              <mx:text><![CDATA[Genre: Fantasy

              Description: Long ago, a feud between Princes Delphus and Lock tore the epic kingdom of Vallon in two. Now, the warring kingdoms of Delphi and Lockland are embroiled in perpetual battle and with Lockland's destruction at hand, the Lockland King orders his Sorcerer to raise the mighty Gryphon in defense. When the gryphon at his command, the Sorcerer then turns on Lockland in an attempt to bring both kingdoms under his evil command.

              Cast: Jonathan LaPaglia, Larry Drake, Amber Benson, Andrew Pleavin, Douglas Roberts, Ashley Artus, Sarah Douglas
              ]]></mx:text>
              </mx:TextArea>
              </mx:Canvas>
              <mx:Canvas label="Death of a President" width="100%" height="100%">
              <mx:TextArea x="10" y="10" width="382" height="265" fontWeight="bold" borderStyle="none">
              <mx:text><![CDATA[Genre: Drama

              Description: Reflecting on a fictional TV broadcast surrounding a truly cataclysmic event, Death of a President centers around the dramatized re-telling of one of the worst events in recent history: The assassination of President George W. Bush on October 18, 2007. Combining archived footage and carefully composed interviews, it paints the picture of the made-up event in shockingly real detail.

              Cast: Robert Mangiardi, Jay Patterson, Brian Boland, Jay Whittaker, Hend Ayoub, Becky Ann Baker, Michael Reilly Burke

              ]]></mx:text>
              </mx:TextArea>
              </mx:Canvas>
              <mx:Canvas label="The King Maker" width="100%" height="100%">
              <mx:TextArea x="10" y="10" height="265" width="382" fontWeight="bold" borderStyle="none">
              <mx:text><![CDATA[Genre: Adventure

              Description: Portuguese mercenary Fernando De Gama has been searching for the man that murdered his father and when his boat capsizes and he is sold into slavery, his buyer is a beautiful young woman… and the daughter of the killer he has been looking for. Appointed to the King's Guard after saving him from an assassination attempt, he must now stop the beautiful Queen from going through with a devious plot to kill him and place her lover on the throne of the kingdom.

              Cast: John Rhys-Davies, Gary Stretch, Dean Alexandrou, Cindy Burbridge, Jonathan Winters, Mark Sobels, Nirut Sirichanya
              ]]></mx:text>
              </mx:TextArea>
              </mx:Canvas>
              <mx:Canvas label="Charlotte's Web" width="100%" height="311">
              <mx:TextArea x="10" y="10" height="265" width="382" fontWeight="bold" borderStyle="none">
              <mx:text><![CDATA[Genre: Family

              Description: Based on the acclaimed book by children's author E.B. White, Charlotte's Web is the story of Wilbur the Pig, Charlotte the Spider and all the animals of the farm who help to save Wilbur from an untimely date with the dinner table. A story of true friendship, it has won the hearts of children and adults around the world with its tale of overcoming obstacles and adversity with a little help from the people that matter the most.

              Cast: Julia Roberts, Steve Buscemi, John Cleese, Oprah Winfrey, Cedric the Entertainer, Dakota Fanning, Thomas Haden Church
              ]]></mx:text>
              </mx:TextArea>
              </mx:Canvas>
              </mx:Accordion>
              <mx:Image id="myImage" height="131" width="96" scaleContent="false" autoLoad="true" x="551" y="120"/>

              </mx:Panel>
              </mx:Application>
              • 4. Re: Image Swap
                justinc9112 Level 1
                shouldn't it be selected index, not new change?

                Thanks for any help