views:

60

answers:

2

private function dataLevel():void {

  //Level 2
  a1=new Array(b1,b2);
  a2=new Array(b3,b4);


  //Level 1
  allA=new Array(a1,a2);


  //trace if the following level exist

  //if the following level exist, create the Branch
  if (allA is Array==true) {
   createBranch(this);

   if (allA[0] is Array==true) {
    createBranch(allA[0]);
   }

   if (allA[1] is Array==true) {
    createBranch(allA[1]);
   }
  }
 }


 private function createBranch(event:Object):void {

  trace(event.target);

}

+1  A: 

Just naming a variable as event won't make it an Event object (and give it a target property). Use trace(event); to trace the passed parameter. Even better, change the variable name to arg1 (argument1) or something that makes more sense.

private function createBranch(arg1:Object):void 
{
    trace(arg1);
}

event is normally used for variables of type Event or its subclasses in an event handler.

Amarghosh
A: 

Sounds like you are basically trying to get something along the lines of a stack trace. You can get a string representation of the stack trace from the Error exception class at runtime, but only in debug mode in Flash Player.

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Error.html#getStackTrace%28%29

private function createBranch(arg1:Object):void 
{
    var stacktrace:String = new Error().getStackTrace();
    //parse 'stacktrace' and do what you want here.
}

Now this only works in the debug versions of the player, 'getStackTrace()' returns null in the standard versions, so this would not work for any production app.

The only other alternative would be to pass a token in to 'createBranch' to indicate where the call came from (which I assume would also determine what type of 'branch' you're creating?) This would be a better approach to keep you logic more clean as well I think:

private function createBranch(arg1:Object, branchType:String):void 
{
    switch(branchType){
        case "type1":
             //create your branch type1 here
             break;
        case "type2":
             //create your branch type2 here
             break;
        case "type3":
             //create your branch type3 here
             break;
    }
}

Something like that.

JStriedl