ActionScript Problem

As I’ve mentioned before I think that there is a lot of promise in using Flex to create applications that are supported by the Flash Communication Server. In order to get more familiar with how Flash Comm Server and Flex interact I started to work through the tutorials on the Flash Comm Dev center and convert them from Flash to Flex. Specifically, I’ve been trying part one of the MP3 Player Tutorial.

Mostly I make small errors in the ActionScript code or the way that Flex handles certain things. It’s annoying but it has helped me learn some of the nuance of the two languages. Unfortunately, these small errors have kept me from getting anything to work. The Flash version works, but my Flex version does not.

I had a hard time debugging the problems with FlashComm and Flex but found a couple of useful resources. One is the Flex Trace Panel which helped me figure out where my current problem is.

I have a Flex interface set up to control the playing and pausing of MP3s (Screenshot). When the user pushes the ‘Activate’ button, the application is supposed to set the label on that button to ‘Deactivate’ and then it is supposed to enable the Pause button and the stop button. Here’s the code:

function start() {

   if (login_pb.getLabel() == “Activate”) {
      mp3_nc = new NetConnection( );
         mp3_nc.onStatus = function (info) {
            Dumper.dump(“The connection code is: “ + info.code);
            Dumper.dump(info.code == “NetConnection.Connect.Success”); //Check to see the status
         
            if( info.code == “NetConnection.Connect.Success” ) {
               //for (var i = 0; i<mp3ArrArtiste.length; i++) {
               //   mp3_lb.addItem(mp3ArrArtiste[i], mp3ArrSong[i]);
               //}
            
               Dumper.dump(“Hello World”); //Check to see if we’re in the if statement.
               stop_pb.enabled = true;
               pause_pb.enabled = true;
            }
         }
            
      mp3_nc.connect(rtmp://myserver/cs_mp3/defstream);
      mp3_ns = new NetStream(mp3_nc);
      id3_ns = new NetStream(mp3_nc);
      
      mp3_ns.onStatus = function(info) {
         Dumper.dump(info.description);
         //if (info.description==“Stopped playing “+selectedMP3+“.”){mp3_title_txt=“”;}
         }
         
      login_pb.setLabel(“Deactivate”);
   }
}

The problem is that when I push the ‘Activate’ button and then run through the check to make sure the connection has been made, the buttons stop responding to changing their ‘enabled’ property. stop_pb.enabled = true and pause_pb.enabled do nothing. Using the FlexTracePanel I can see that it is running through the if statement and if I move the two .enabled = true lines from the mp3_ns.onStatus = function(info) they work just fine. Something with that onStatus function is causing the problem but I haven’t figured it out yet.

That’s the project for tomorrow.

No related posts.