Skip navigation
Currently Being Moderated

I have a button that keeps blowing up my code

May 30, 2012 8:27 AM

can someone take a look and tell me why? I have imported the classes

 

package {
import flash.display.MovieClip;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
    import com.yahoo.astra.fl.controls.Tree; 
import com.yahoo.astra.fl.controls.treeClasses.*;
import flash.events.MouseEvent;
import fl.controls.Button;


public class VideoPlaylistNoThumb extends MovieClip {
  private var xmlLoader:URLLoader;
  public var btnNext:Button;
  //btnNext.label = "Next";
 
 
  public function VideoPlaylistNoThumb():void {
   // Load the playlist file, then initialize the media player.
   xmlLoader = new URLLoader();
   xmlLoader.addEventListener(Event.COMPLETE, initMediaPlayer);
   xmlLoader.load(new URLRequest("playlist2.xml"));
  }
 
  public function initMediaPlayer(event:Event):void {
   var myXML:XML = new XML(xmlLoader.data);
   var item:XML;
   for each(item in myXML.vid) { // populate playlist.
    // Send data to List.
    videoList.addItem({label:item.attribute("desc").toXMLString(),
    data:item.attribute("src").toXMLString(),
    data:item.attribute("id").toXMLString(),
    data:item.attribute("wNnext").toXMLString(),
    data:item.attribute("aNext").toXMLString(),
    data:item.attribute("allNext").toXMLString(),
    ttURL:item.attribute("ttURL").toXMLString()});
}  
   // Select the first video.
   videoList.selectedIndex = 0;
   myVid.autoRewind = true;
   // Listen for item selection.
   videoList.addEventListener(Event.CHANGE, listListener);
   // And automatically load it into myVid.
   myVid.source = videoList.selectedItem.data;
   myVidCaptioning.source = videoList.selectedItem.ttURL;
   myVidCaptioning.flvPlayback = myVid;
   // Pause video until selected or played.
   //myVid.pause();
}  

  // Detect when new video is selected, and play it
  function listListener(event:Event):void {
   myVid.stop();
   myVidCaptioning.source = event.target.selectedItem.ttURL;
   myVidCaptioning.showCaptions = false;
   myVidCaptioning.showCaptions = true;
   myVid.autoPlay = true;
   myVid.play(event.target.selectedItem.data);

  }
 
   function clickHandler(event:MouseEvent):void {
      trace("I have been clicked");
  }

  btnNext.addEventListener(MouseEvent.CLICK, clickHandler); 

}

}

 

It is not recognizing btnNext

 
Replies
  • Currently Being Moderated
    May 30, 2012 9:27 AM   in reply to dpattersonCBT

    What kind of button you're using whatever turn it into the library symbol and a name asiganela "As Linkage", something like myButton

    and in your code

      public var btnNext: myButton = new myButton ();

       addChild (btnNext);

     
    |
    Mark as:
  • Currently Being Moderated
    May 30, 2012 9:58 AM   in reply to dpattersonCBT
    ok, in the library click the right button on your btnNext symbol, then select the option "Properties", then select "advanced" (bottom left), then check "Export for ActionScript", and in the field Class type:

    myButton

    Now use the code before you send

     

     
    |
    Mark as:
  • Currently Being Moderated
    May 30, 2012 10:29 AM   in reply to dpattersonCBT

    Maybe you need a constructor

     

     

     

    public class VideoPlaylistNoThumb extends MovieClip {

     

      private var xmlLoader:URLLoader;

      public var btnNext:myButton ;

     

      public funtion VideoPlaylistNoThumb():void{

           btnNext= new myButton ();

          addChild (btnNext);

      }

     

    //more code

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 1, 2012 2:26 PM   in reply to dpattersonCBT

    if your button is already part of the display list, you can probably remove public var btnNext:Button; ... and just go back to your original code, forget all the other responses, and add the button listener here instead:

     

    public function VideoPlaylistNoThumb():void {

               btnNext.addEventListener(MouseEvent.CLICK, clickHandler);

              // Load the playlist file, then initialize the media player.

              xmlLoader = new URLLoader();

              xmlLoader.addEventListener(Event.COMPLETE, initMediaPlayer);

              xmlLoader.load(new URLRequest("playlist2.xml"));

    }

     

    //---

     

    however, if your button is NOT already part of the display list, you DO need public var btnNext:Button; and then you'd have to ADD it to the display list like this:

     

    public var btnNext:Button;

    public function VideoPlaylistNoThumb():void {

              btnNext = new btnNext();

              addChild(btnNext);

              btnNext.addEventListener(MouseEvent.CLICK, clickHandler);

              // Load the playlist file, then initialize the media player.

              xmlLoader = new URLLoader();

              xmlLoader.addEventListener(Event.COMPLETE, initMediaPlayer);

              xmlLoader.load(new URLRequest("playlist2.xml"));

    }

     

    keep in mind that the btnNext will need the actionscript linkage identifier "btnNext" and check the box for "export for actionscript" and "export in frame 1" ... you can set these in the properties of the library symbol.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points