Mailing List
Home
Flash Pro
Extending Flash
Flash Macromedia Developer
Subjects
Firework Effect
setInterval bug identified and fixed
setInterval bug identified and fixed
ScrollPane component doesn 't auto update
Help: MX 2004 How to script a print button to print the entire sli
Event Dispatcher between classes
memory management removeMovieClip /
MX2004 Dataset itemClassName
Order of events per frame
XML to Object help
Textfield prototype question
Flash and QuickTime VR
Reading and displaying RSS feeds in Flash MX
Flash MX 2004 Sucks
AW: [Flashcoders] Switch/Case vs If/else
AW: [Flashcoders] Switch/Case vs If/else
Flash Interface with 10mb xml file
Web Service Results
Listener Object 's best practice
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
protected members in AS1

protected members in AS1

2004-02-24       - By Victor W Allen

 Back
Reply:     1     2     3     4     5  

So, I was playing around with private properties etc., as described here:
http://www.crockford.com/javascript/private.html
...and I thought, "Is it possible to simulate protected members? "

This is what I came up with, any thoughts? Apologies if this is
covering old ground on the list...

V

function SuperClass(value1,value2) {
var _protected = {}; // private object holds the protected members
var _self = this; // internal methods don 't have access to "this "
var _member1 = value1;
var _member2 = value2;
var _getMember1 = function() { return _member1; };
var _setMember1 = function(value1) { _member1 = value1; };

_protected.addProperty( 'member1 ',_getMember1,_setMember1);
_protected._member2 = value2;
_protected._protectedMethod = function() { return _self; }; //
protected methods need to use _self

return _protected; // ignored when creating a new SuperClass, but
not when called as super()
}
SuperClass.prototype.toString = function() { return "[ object SuperClass
] "; };

function SubClass(value1,value2) {

var _protected = super(value1,value2); // catch those protected members

this.getMember1 = function() { return _protected.member1; };
this.getMember2 = function() { return _protected._member2; };
this.publicMethod = function() { return
_protected._protectedMethod(); };

return _protected; // just SubSubClass, should get that protected
stuff too
}
SubClass.prototype = new SuperClass();
SubClass.prototype.toString = function() { return "[ object SubClass ] "; };

sub = new SubClass( "Uno ", "Dos ");
trace(sub.getMember1());
trace(sub.getMember2());
trace(sub.publicMethod());


=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Supported by Fig Leaf Software
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Be sure to check the archives and the wiki:
http://chattyfig.figleaf.com/
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:105028
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)