9 Replies Latest reply: May 23, 2012 6:27 AM by sinious RSS

    1120: Access of undefined property

    Venkom Community Member

      i include Bandwidth Test  in my actionScript Project file. but i getting this error.

       

      Error is:

       

      Scene 1, Layer 'actions', Frame 1, Line 171120: Access of undefined property bandwidthTotal.

       

      Main actionScript Project

       

      Line 17 is :


      import com.example.Bandwidth;
      
      15.  var mytext:TextField = new TextField();
      16.  addChild(mytext);
      17.  mytext.text = bandwidthTotal;
      

       

       

      external  .as file


      package com.example
      {
          import flash.display.Sprite;
          import flash.net.NetConnection;
          import flash.events.NetStatusEvent;
          import flash.events.AsyncErrorEvent;
      
           public class Bandwidth extends Sprite
          {
              private var nc:NetConnection;
      
              public function Bandwidth()
              {
                  nc = new NetConnection();
                  nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
                  nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
                  nc.client = new Client();
                  nc.connect("rtmp://xxx.xx.xxx.xx/bwcheck");
              }
      
      
              public function netStatusHandler(event:NetStatusEvent):void
              {
                  trace(event.info.code);
                  switch (event.info.code)
                  {
                      case "NetConnection.Connect.Success":
                                nc.call("checkBandwidth", null);
                                break;
                    }
              }
      
             public function asyncErrorHandler(event:AsyncErrorEvent):void
              {
                          // Handle asyncErrorEvents. 
              }
          }
      }
      
      
      class Client {
           public function onBWCheck(... rest):Number {
                              return 0;
           }
      
                 public function onBWDone(... rest):void {
                              var bandwidthTotal:Number;
                              if (rest.length > 0){
                                    bandwidthTotal = rest[0];
      
                               trace("Bandwidh from server to client is: " + bandwidthTotal + " Kbps");
      
                               }
                }
      }
      
      
        • 1. Re: 1120: Access of undefined property
          kglad MVP

          that's not an external as file.  it's a class file.

           

          plus you will have other problems if you try and access bandwidthTotal from outside onBWDone().

           

          if you want some other class to reference a variable in Client, expose that variable by making it public and not local to onBWDone().   you'll then need to understand something about how class files work.

          • 2. Re: 1120: Access of undefined property
            Venkom Community Member

            Ok,

            how to make  "bandwidthTotal" visible in text feild of my main flash file.

            • 3. Re: 1120: Access of undefined property
              sinious MVP

              Expose a method to get the current bandwidthTotal from the Client class who's initiating and tracking the bandwidth (I assume plenty of code is missing from it). Do that by making a private property and a getter.

               

              e.g.

              class Client {      // keep track of bandwidth on a class level      private var _currentBandwidthTotal:Number = 0;            // allow outside classes to access the current bandwidth      public function get BandwidthTotal():Number      {           return _currentBandwidthTotal;      }            public function onBWCheck(... rest):Number {           return 0;      }            public function onBWDone(... rest):void {           if (rest.length > 0){                _currentBandwidthTotal = rest[0];                                trace("Bandwidh from server to client is: " + _currentBandwidthTotal + " Kbps");           }      } }

               

              Your client class will now let you get the current bandwidth by instantiating the Client class and using using myClientObj.BandwidthTotal();.

               

              You're going to need to make sure you set _currentBandwidthTotal = 0 every time you start a new download but I presume there's plenty of code missing here so you'd do that upon initting a new download.

              • 4. Re: 1120: Access of undefined property
                Venkom Community Member

                But i getting same error.

                or this is possible to change timline action script..?

                • 5. Re: 1120: Access of undefined property
                  sinious MVP

                  Let's try making this simple. I assume you're doing this in a frame script so lets let Client extend Sprite so it can set the TextField directly.

                   

                  Use your original code from your original post. Make sure your server supports bandwidth detection (I'll assume it does, because by default it's enabled). If it's not enabled here's how you do it:

                   

                  http://help.adobe.com/en_US/flashmediaserver/devguide/WS5b3ccc516d4fbf351e63e3d11a0773d56e -7ffaDev.html#WS5b3ccc516d4fbf351e63e3d11a0773d117-7ffbDev

                   

                  Now remove line 17:

                  mytext.text = bandwidthTotal;

                   

                  Now adjust your Client class like so:

                   

                  class Client extends Sprite {
                       public function onBWCheck(... rest):Number {
                          return 0;
                       }

                       public function onBWDone(... rest):void {

                          if (rest.length > 0) {

                               mytext.text = rest[0]; // directly set the TextField

                           }
                      }
                  }

                  • 6. Re: 1120: Access of undefined property
                    Venkom Community Member

                    i'm getting another error

                     

                    D:\Bandwidth.as, Line 15006: An ActionScript file can not have more than one externally visible definition: mytext, Bandwidth

                     

                    i don't know how to work classes. so that is the reson for some errors.

                    i working in timeline actionscript. so pls give me advice

                     

                    Total Code:

                    package

                    {

                              import flash.display.Sprite;

                              import flash.net.NetConnection;

                              import flash.events.NetStatusEvent;

                              import flash.events.AsyncErrorEvent;

                              import flash.text.TextField;

                     

                              var mytext:TextField = new TextField();

                              addChild(mytext);

                     

                              public class Bandwidth extends Sprite

                              {

                                        private var nc:NetConnection;

                     

                                     public function Bandwidth()

                                        {

                                                  nc = new NetConnection();

                                                  nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

                                                  nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);

                                                  nc.client = new Client();

                                                  nc.connect("rtmp://server.host.com/bwcheck");

                                        }

                     

                                        public function netStatusHandler(event:NetStatusEvent):void

                                        {

                                                  trace(event.info.code);

                                                  switch (event.info.code)

                                                  {

                                                            case "NetConnection.Connect.Success" :

                     

                                                                      nc.call("checkBandwidth", null);

                                                                      break;

                                                  }

                                        }

                     

                                        public function asyncErrorHandler(event:AsyncErrorEvent):void

                                        {

                                                  // Handle asyncErrorEvents.

                                        }

                              }

                    }

                     

                    class Client extends Sprite {

                     

                     

                         public function onBWCheck(... rest):Number {

                            return 0;

                         }

                     

                     

                         public function onBWDone(... rest):void {

                            if (rest.length > 0) {

                                 mytext.text = rest[0];

                             }

                        }

                    }

                    • 7. Re: 1120: Access of undefined property
                      sinious MVP

                      I'll just build a full example with a custom event and break out the Client class to transmit that event all the way back to the main class, and then display bandwidth. I saved the FLA down to Flash CS4, I don't know what version you have.

                       

                      Full Bandwidth Test Example (8kb)

                       

                      I added trace statements so the events being daisy chained will be easy to see. This is the same basic thing as your code except using events to send the bandwidth back to the main class so it can "do whatever it wants". I made my own TextField and I simply display the result there.

                       

                      Change the RTMP URL accordingly.

                      • 8. Re: 1120: Access of undefined property
                        Venkom Community Member

                        yaa it's working great. Thank you Mr.sinious.

                        • 9. Re: 1120: Access of undefined property
                          sinious MVP

                          Most welcome.