-
1. Re: 1120: Access of undefined property
kglad May 14, 2012 7:16 AM (in response to Venkom)1 person found this helpfulthat'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 May 15, 2012 5:18 AM (in response to kglad)Ok,
how to make "
bandwidthTotal" visible in text feild of my main flash file.
-
3. Re: 1120: Access of undefined property
sinious May 15, 2012 6:40 AM (in response to Venkom)1 person found this helpfulExpose 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 May 21, 2012 10:18 AM (in response to sinious)But i getting same error.
or this is possible to change timline action script..?
-
5. Re: 1120: Access of undefined property
sinious May 21, 2012 1:00 PM (in response to Venkom)1 person found this helpfulLet'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:
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 May 22, 2012 3:34 AM (in response to sinious)i'm getting another error
D:\Bandwidth.as, Line 1 5006: 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 May 22, 2012 7:57 AM (in response to Venkom)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 May 22, 2012 11:03 AM (in response to sinious)yaa it's working great. Thank you Mr.sinious.
-
9. Re: 1120: Access of undefined property
sinious May 23, 2012 6:27 AM (in response to Venkom)Most welcome.