• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

1120: Access of undefined property

Engaged ,
May 14, 2012 May 14, 2012

Copy link to clipboard

Copied

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");

                         }

          }

}

TOPICS
ActionScript

Views

1.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 22, 2012 May 22, 2012

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

...

Votes

Translate

Translate
Community Expert ,
May 14, 2012 May 14, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 15, 2012 May 15, 2012

Copy link to clipboard

Copied

Ok,

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 15, 2012 May 15, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 21, 2012 May 21, 2012

Copy link to clipboard

Copied

But i getting same error.

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 21, 2012 May 21, 2012

Copy link to clipboard

Copied

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.h...

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

         }
    }
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 22, 2012 May 22, 2012

Copy link to clipboard

Copied

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];

         }

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 22, 2012 May 22, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 22, 2012 May 22, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 23, 2012 May 23, 2012

Copy link to clipboard

Copied

LATEST

Most welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines