m1cky
01-06-2005, 04:30 PM
Hello,
i have a problem with object references.
In my concrete case i create 1 object (with new), this object creates 3 another objects and passes each of them 'this' as reference to the parent for further callbacks. Here comes the ****, in the body of constructor that reference is valid, i store it in a member-variable (doesnt matter which type, never worked) as far as good. If the constructor is left and i try to access the parent object over the stored reference it does not work. If i trace the content of the member it says "undefined" !
What is the mistake ?? Pls help
Here the code :
import FHW_MenuGroup;
class FHW_Menu implements IFHW_Menu
{
var MenuGroups:Array = new Array();
function FHW_Menu()
{
InsertGroup(new FHW_MenuGroup("Button1", GetNumberOfGroups() + 1, this));
InsertGroup(new FHW_MenuGroup("Button2", GetNumberOfGroups() + 1, this));
InsertGroup(new FHW_MenuGroup("Button3", GetNumberOfGroups() + 1, this));
RearrangeGroups();
}
function InsertGroup(Group:FHW_MenuGroup)
{
MenuGroups.push(Group);
}
function RearrangeGroups()
{
var GroupIndex:Number = 0;
var NextGroupYcoo:Number = 0;
trace(GetNumberOfGroups() + " items total. Rearranging...")
for(; GroupIndex < MenuGroups.length; GroupIndex++)
{
trace("Item " + GroupIndex + " moving to 0, " + NextGroupYcoo);
MenuGroups[GroupIndex].MoveTo(0, NextGroupYcoo);
NextGroupYcoo += MenuGroups[GroupIndex].GetVerticalSize();
}
}
function GetNumberOfGroups()
{
return MenuGroups.length;
}
}
//#include "IFHW_Menu.as"
class FHW_MenuGroup
{
function FHW_MenuGroup(MovieRessourceId:String, Depth:Number, m:Object)
{
trace ("FHW_MenuGroup instantiated on depth " + Depth);
clip = _root.createEmptyMovieClip("button", Depth);
clip.attachMovie(MovieRessourceId, "Bt1", 10);
clip.onRollOver = this.ExpandMenu;
clip.onRollOut = this.ContractMenu;
menux = m;
}
function AddMenuItem(Label:String, Address:String)
{
}
function ExpandMenu()
{
trace("rolling over");
CurrentExpandSize = 30;
//undefined !!!
trace(this.menux);
trace(CurrentExpandSize);
menux.RearrangeGroups();
}
function ContractMenu()
{
trace("rolling out");
CurrentExpandSize = 0;
}
function GetVerticalSize()
{
return clip._height + CurrentExpandSize;
}
function MoveTo(x:Number, y:Number)
{
trace("Moving to: " + x + ", " + y);
clip._x = x;
clip._y = y;
}
var Items:Array = new Array();
var CurrentExpandSize:Number = 0;
var clip:MovieClip;
var menux:Object;
}
i have a problem with object references.
In my concrete case i create 1 object (with new), this object creates 3 another objects and passes each of them 'this' as reference to the parent for further callbacks. Here comes the ****, in the body of constructor that reference is valid, i store it in a member-variable (doesnt matter which type, never worked) as far as good. If the constructor is left and i try to access the parent object over the stored reference it does not work. If i trace the content of the member it says "undefined" !
What is the mistake ?? Pls help
Here the code :
import FHW_MenuGroup;
class FHW_Menu implements IFHW_Menu
{
var MenuGroups:Array = new Array();
function FHW_Menu()
{
InsertGroup(new FHW_MenuGroup("Button1", GetNumberOfGroups() + 1, this));
InsertGroup(new FHW_MenuGroup("Button2", GetNumberOfGroups() + 1, this));
InsertGroup(new FHW_MenuGroup("Button3", GetNumberOfGroups() + 1, this));
RearrangeGroups();
}
function InsertGroup(Group:FHW_MenuGroup)
{
MenuGroups.push(Group);
}
function RearrangeGroups()
{
var GroupIndex:Number = 0;
var NextGroupYcoo:Number = 0;
trace(GetNumberOfGroups() + " items total. Rearranging...")
for(; GroupIndex < MenuGroups.length; GroupIndex++)
{
trace("Item " + GroupIndex + " moving to 0, " + NextGroupYcoo);
MenuGroups[GroupIndex].MoveTo(0, NextGroupYcoo);
NextGroupYcoo += MenuGroups[GroupIndex].GetVerticalSize();
}
}
function GetNumberOfGroups()
{
return MenuGroups.length;
}
}
//#include "IFHW_Menu.as"
class FHW_MenuGroup
{
function FHW_MenuGroup(MovieRessourceId:String, Depth:Number, m:Object)
{
trace ("FHW_MenuGroup instantiated on depth " + Depth);
clip = _root.createEmptyMovieClip("button", Depth);
clip.attachMovie(MovieRessourceId, "Bt1", 10);
clip.onRollOver = this.ExpandMenu;
clip.onRollOut = this.ContractMenu;
menux = m;
}
function AddMenuItem(Label:String, Address:String)
{
}
function ExpandMenu()
{
trace("rolling over");
CurrentExpandSize = 30;
//undefined !!!
trace(this.menux);
trace(CurrentExpandSize);
menux.RearrangeGroups();
}
function ContractMenu()
{
trace("rolling out");
CurrentExpandSize = 0;
}
function GetVerticalSize()
{
return clip._height + CurrentExpandSize;
}
function MoveTo(x:Number, y:Number)
{
trace("Moving to: " + x + ", " + y);
clip._x = x;
clip._y = y;
}
var Items:Array = new Array();
var CurrentExpandSize:Number = 0;
var clip:MovieClip;
var menux:Object;
}