[Flashcoders] Scope problems

2006-04-25 Thread Asai



I'm having some frustrating problems with scope in trying to author 
some classes.  Basically, how do I get a value which is nested in a 
function, returned to update the value of a given property?  I've got 
several functions nested inside a public function which includes 
function literals. In the following code I just want to be able to 
have the returnBW function update the value of the vidQuality 
property.  But I can't figure out how to return it?  Any knowledge?


thanks.

class classes.CheckBW {
var nc:NetConnection;
var ns:NetStream;
var whichServer;
var counter;
var vidQuality:String;
public function bwCheck(whichServer):Void{
nc = new NetConnection();
nc.onStatus = function(info) {
trace(Level: +info.level+ Code: +info.code);
NetConnection.prototype.onBWDone = function(p_bw) {
trace(onBWDone: +p_bw);
if (p_bw != undefined) {
returnBW(p_bw);
}
};
function returnBW(p_bw) {
trace(returnBW called);
if (p_bw=400) {
vidQuality = 
_med;

} else if (p_bw400  p_bw=150) {
vidQuality = 
_low;

} else if (p_bw150) {
vidQuality = 
_low;

}
}
NetConnection.prototype.onBWCheck = function() {
return ++counter;
// Serverside, just ignore any 
return value and return the call count

};

};
nc.connect(whichServer);
nc.call(checkBandwidth, null);


}

}

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Scope problems

2006-04-25 Thread Cedric Muller

what about:

class classes.CheckBW {
var nc:NetConnection;
var ns:NetStream;
var whichServer;
var counter;
var vidQuality:String;
var owner:Object = this;
public function bwCheck(whichServer):Void{
nc = new NetConnection();
nc.onStatus = function(info) {
trace(Level: +info.level+ Code:  
+info.code);
NetConnection.prototype.onBWDone = function 
(p_bw) {

trace(onBWDone: +p_bw);
if (p_bw != undefined) {
owner.returnBW(p_bw);
}
};
function returnBW(p_bw) {
trace(returnBW called);
if (p_bw=400) {
vidQuality = _med;
} else if (p_bw400  p_bw=150) {
vidQuality = _low;
} else if (p_bw150) {
vidQuality = _low;
}
}
NetConnection.prototype.onBWCheck = function 
() {

return ++counter;
// Serverside, just ignore any  
return value and return the call count

};

};
nc.connect(whichServer);
nc.call(checkBandwidth, null);


}

}


??
(just added the 'owner')

hth,
cedric




class classes.CheckBW {
var nc:NetConnection;
var ns:NetStream;
var whichServer;
var counter;
var vidQuality:String;
public function bwCheck(whichServer):Void{
nc = new NetConnection();
nc.onStatus = function(info) {
trace(Level: +info.level+ Code:  
+info.code);
NetConnection.prototype.onBWDone = function 
(p_bw) {

trace(onBWDone: +p_bw);
if (p_bw != undefined) {
returnBW(p_bw);
}
};
function returnBW(p_bw) {
trace(returnBW called);
if (p_bw=400) {
vidQuality = _med;
} else if (p_bw400  p_bw=150) {
vidQuality = _low;
} else if (p_bw150) {
vidQuality = _low;
}
}
NetConnection.prototype.onBWCheck = function 
() {

return ++counter;
// Serverside, just ignore any  
return value and return the call count

};

};
nc.connect(whichServer);
nc.call(checkBandwidth, null);


}

}


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Scope problems

2006-04-25 Thread Asai


Hey Cedric, thanks a lot, man!  It works. That was just killing me. 
Sometimes it doesn't matter how many O'Reilly books you read, you 
gotta have someone tell you how it is.

Thanks again!

At 12:18 PM 4/25/2006, you wrote:

what about:

class classes.CheckBW {
var nc:NetConnection;
var ns:NetStream;
var whichServer;
var counter;
var vidQuality:String;
var owner:Object = this;
public function bwCheck(whichServer):Void{
nc = new NetConnection();
nc.onStatus = function(info) {
trace(Level: +info.level+ Code:
+info.code);
NetConnection.prototype.onBWDone = function (p_bw) {
trace(onBWDone: +p_bw);
if (p_bw != undefined) {
owner.returnBW(p_bw);
}
};
function returnBW(p_bw) {
trace(returnBW called);
if (p_bw=400) {
vidQuality = _med;
} else if (p_bw400  p_bw=150) {
vidQuality = _low;
} else if (p_bw150) {
vidQuality = _low;
}
}
NetConnection.prototype.onBWCheck = function () {
return ++counter;
// Serverside, just ignore any
return value and return the call count
};

};
nc.connect(whichServer);
nc.call(checkBandwidth, null);


}

}


??
(just added the 'owner')

hth,
cedric




class classes.CheckBW {
var nc:NetConnection;
var ns:NetStream;
var whichServer;
var counter;
var vidQuality:String;
public function bwCheck(whichServer):Void{
nc = new NetConnection();
nc.onStatus = function(info) {
trace(Level: +info.level+ Code:
+info.code);
NetConnection.prototype.onBWDone = function (p_bw) {
trace(onBWDone: +p_bw);
if (p_bw != undefined) {
returnBW(p_bw);
}
};
function returnBW(p_bw) {
trace(returnBW called);
if (p_bw=400) {
vidQuality = _med;
} else if (p_bw400  p_bw=150) {
vidQuality = _low;
} else if (p_bw150) {
vidQuality = _low;
}
}
NetConnection.prototype.onBWCheck = function () {
return ++counter;
// Serverside, just ignore any
return value and return the call count
};

};
nc.connect(whichServer);
nc.call(checkBandwidth, null);


}

}


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


---asai 


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com