3 Replies Latest reply on Apr 8, 2011 8:28 PM by Abhinav Sharma

    beginner help with "next" arrow button




      I have a simple  video gallery set up connected to an xml file to load my assets (video  path, title, description).  Rather than using small thumbnails to change  the videos and corresponding info, I have two arrow buttons that should  change the videos in order back and forth.  (so 0 > 1 > 2 > 0  etc, and backwards with the left arrow)


      My assets are  connected and I know this is simple and I have learned it but I am  having trouble with my assets changing to my button click events.  I was  thinking of using if statements (which work on the first 2 assets but  then fail after that).


      protected function button1_clickHandler(event:MouseEvent):void
                      if (myVideo.source == "assets/media/" + myData[0].path;
                      myLabel1.text == myData[0].desc;
                      titleLabel1.text == myData[0].title;)
                      myVideo.source = "assets/media/" + myData[1].path;
                      myLabel1.text = myData[1].desc;
                      titleLabel1.text = myData[1].title;


      in my head i was thinking of then using "else if" myData[1] then it changes to [2] like this:


      else if (myVideo.source = "assets/media/" + myData[1].path;
                      myLabel1.text = myData[1].desc;
                      titleLabel1.text = myData[1].title;)
                  { myVideo.source = "assets/media/" + myData[2].path;
                      myLabel1.text = myData[2].desc;
                      titleLabel1.text = myData[2].title; }


      but i seem to be doing something wrong.


      can anyone help me with the code to loop them all together?



        • 1. Re: beginner help with "next" arrow button
          Abhinav Sharma Level 2

          try something like this. hope it works.


                  var currentIndex = 0;
                  var totalVideos = arrColl.length(); // replace by your count logic
                  public function click_NextHandler(e:Event)
                      if(currentIndex == totalVideos)
                          currentIndex = 0;
                      // set video properties
                      myVideo.source       = "assets/media/" + myData[currentIndex].path;
                      myLabel1.text        = myData[currentIndex].desc;
                      titleLabel1.text     = myData[currentIndex].title;            







          1 person found this helpful
          • 2. Re: beginner help with "next" arrow button
            oneL0ve_ Level 1

            thanks, but I'm getting an error for this line here:


            var totalVideos = arrColl.length(3);


            I'm assuming arrColl is "array collection", but not sure what I'm supposed to link it to?

            • 3. Re: beginner help with "next" arrow button
              Abhinav Sharma Level 2

              Yes, its ArrayCollection. It holds data. In your case, collection of videos.

                  <mx:ArrayCollection id="myData">
                              <mx:Object source="Video1.mp4" title="Hello Friend" />
                              <mx:Object source="Video2.mp4" title="Hw ru?" />
                              <mx:Object source="Video3.mp4" title="Hv a nice day!" />


              Also you can use XML. Lets your XML data is like -

                          private var myDataXML:XML = 
                                                          <title>Hello Friend</title>
                                                          <title>How r u!</title>
                                                          <title>Have a nice day!!</title>


              Note: You can populate this XML  data from external XML file too.


              Now, on button click,

                          private function click_NextHandler(e:Event):void
                              if(currentIndex == myDataXML.mydata.length())
                                  currentIndex = 0;
                          myVideo.source       = "assets/media/" + myDataXML.mydata[currentIndex].source;
                          titleLabel1.text     = myDataXML.mydata[currentIndex].title;            }



              Hope it helps.