csdstudio
09-10-2006, 01:24 AM
This is driving me nuts, can someone explain why this is happening? The following code shows MainClass implementing Iextendable with a public var "owner". After instantiating that class you cannot set or retrieve the value of owner.
package
{
import flash.display.Sprite;
//
public class Doc extends Sprite
{
// PRIVATE PROPERTIES --------------------------------------------------------------------------------------------------
var ext1:Iextendable;
// CONSTRUCTOR ---------------------------------------------------------------------------------------------------------
public function Doc()
{
ext1=new MainClass();
trace(ext1.owner);// compiler error, not found
trace(ext1.ownerID);
}
}
//
interface Iextendable
{
function get ownerID():String;
}
//
class MainClass implements Iextendable
{
public var owner:String="owner string";
private var _ownerID:Number;
public function extendable(){
}
public function get ownerID():Number
{
return _ownerID;
}
}
}
Now if I change the data type of ext1 to MainClass it works fine:
package
{
import flash.display.Sprite;
//
public class Doc extends Sprite
{
// PRIVATE PROPERTIES --------------------------------------------------------------------------------------------------
var ext1:MainClass; //changed type from 'Iextendable'
// CONSTRUCTOR ---------------------------------------------------------------------------------------------------------
public function Doc()
{
ext1=new MainClass();
trace(ext1.owner);// now traces "owner string"
trace(ext1.ownerID);
}
}
//
interface Iextendable
{
function get ownerID():String;
}
//
class MainClass implements Iextendable
{
public var owner:String="owner string";
private var _ownerID:Number;
public function extendable(){
}
public function get ownerID():Number
{
return _ownerID;
}
What this tells me is any variable not declared in the interface getter/setter requirements, cannot be accessed. That doesn't make sense.
package
{
import flash.display.Sprite;
//
public class Doc extends Sprite
{
// PRIVATE PROPERTIES --------------------------------------------------------------------------------------------------
var ext1:Iextendable;
// CONSTRUCTOR ---------------------------------------------------------------------------------------------------------
public function Doc()
{
ext1=new MainClass();
trace(ext1.owner);// compiler error, not found
trace(ext1.ownerID);
}
}
//
interface Iextendable
{
function get ownerID():String;
}
//
class MainClass implements Iextendable
{
public var owner:String="owner string";
private var _ownerID:Number;
public function extendable(){
}
public function get ownerID():Number
{
return _ownerID;
}
}
}
Now if I change the data type of ext1 to MainClass it works fine:
package
{
import flash.display.Sprite;
//
public class Doc extends Sprite
{
// PRIVATE PROPERTIES --------------------------------------------------------------------------------------------------
var ext1:MainClass; //changed type from 'Iextendable'
// CONSTRUCTOR ---------------------------------------------------------------------------------------------------------
public function Doc()
{
ext1=new MainClass();
trace(ext1.owner);// now traces "owner string"
trace(ext1.ownerID);
}
}
//
interface Iextendable
{
function get ownerID():String;
}
//
class MainClass implements Iextendable
{
public var owner:String="owner string";
private var _ownerID:Number;
public function extendable(){
}
public function get ownerID():Number
{
return _ownerID;
}
What this tells me is any variable not declared in the interface getter/setter requirements, cannot be accessed. That doesn't make sense.