Forum ActionScript 3.0 Function anonymous - errors - removeChild

Problems and discussions relating to ActionScript 3.0 here.

Function anonymous - errors - removeChild

Postby Turrican » January 20th, 2012, 1:21 am

What is the "Function Anonymous" ?
I´m getting a lot of errors when I use removeChild from AS3. And many of them display this "Function anonymous" like this:
Can´t I remove a child?

TypeError: Error #1034: Falha de coerção de tipo: não é possível converter Function em flash.display.DisplayObject.
at MethodInfo-490()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at bridge::Connection/handleMessage()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at bridge.utils::BinarySerializer/onMessage()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at MessageBuilder/AddValue()
at bridge.utils::BinarySerializer/onValue()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at TokenBuilder/AddByte()
at bridge.utils::BinarySerializer/AddByte()
at Function/<anonymous>()


I´m trying to go from one class to another (the menu screen to the game) and I´m getting the error above.
Last edited by Turrican on January 20th, 2012, 1:27 am, edited 1 time in total.
Turrican
 
Posts: 23
Joined: August 11th, 2011, 11:50 pm

Re: Function anonymous - errors

Postby Benjaminsen » January 20th, 2012, 1:26 am

The Player.IO error log will show you the context of the error.

The method that does error is however the result of an handleMessageHandler

/Chris

Turrican wrote:What is the "Function Anonymous" ?
I´m getting a lot of errors and many of them display this "Function anonymous" like this:

TypeError: Error #1034: Falha de coerção de tipo: não é possível converter Function em flash.display.DisplayObject.
at MethodInfo-490()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at bridge::Connection/handleMessage()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at bridge.utils::BinarySerializer/onMessage()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at MessageBuilder/AddValue()
at bridge.utils::BinarySerializer/onValue()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at TokenBuilder/AddByte()
at bridge.utils::BinarySerializer/AddByte()
at Function/<anonymous>()


I´m trying to go from one class to another (the menu screen to the game) and I´m getting the error above.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Function anonymous - errors - removeChild

Postby Turrican » January 20th, 2012, 1:28 am

I always get this error when I use a removeChild.
Can´t I remove a child when I use PlayerIO?
Turrican
 
Posts: 23
Joined: August 11th, 2011, 11:50 pm

Re: Function anonymous - errors - removeChild

Postby Benjaminsen » January 20th, 2012, 1:32 am

Turrican wrote:I always get this error when I use a removeChild.
Can´t I remove a child when I use PlayerIO?


Paste the code that errors, let's look at what you are doing.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Function anonymous - errors - removeChild

Postby Turrican » January 20th, 2012, 1:39 am

I´ll try to explain :)

I´m doing this:

Main class -> calls Menu class -> calls ChatLoby class (instantiate the lobby and chat).
When 2 players join a room, I go to the Formation Screen (another class), where the players choose the formation for their teams (it´s a soccer game):


Code: Select all
      if(Main.isOnline)  // a variable to tell me if the game is online or offline(2 players on same machine)
         {
            startBt.visible=false;
            startBt.removeEventListener(MouseEvent.CLICK,onStart);
            startBt.removeEventListener(MouseEvent.MOUSE_OVER, overPlay);            
         
            okA.addEventListener(MouseEvent.CLICK, okAbt);
            okB.addEventListener(MouseEvent.CLICK, okBbt);
            
            Main.connection.addMessageHandler("ok1", function(m:Message, ok1:Boolean){
               trace("oka");
               ok0=ok1;
               trace("a: " + ok0 + ok00);
               if(ok0 && ok00)
               {
                  removeListeners();
                  Main.gameState="jogo";
                  Main.formationA=formA;
                  Main.formationB=formB;
                  dispatchEvent(new Event("Init",true));
                  parent.removeChild(this);      
               }

            })         


So, when I use the parent.removeChild(this), I got this error
PS: this error happens only when I use PlayerIO. This game works ok offline (2 players at same machine), but now I´m trying to implement PlayerIO and some things (like removeChild) give this error... :)

Thanks!
Turrican
 
Posts: 23
Joined: August 11th, 2011, 11:50 pm

Re: Function anonymous - errors - removeChild

Postby Benjaminsen » January 20th, 2012, 1:42 am

When calling an anonymous method the this reference is lost as the scope is not preserved.

There are two easy ways to solve that, either call a private method on your class directly or use the below hack.

Code: Select all
var that:Type = this;
....(function():void{
   that.parent.removeChild(that)
})
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Function anonymous - errors - removeChild

Postby Turrican » January 20th, 2012, 1:52 am

Oh yeah!!!
Now I understood!!!!
This is why I´m getting some errors... thanks a lot!
SOLVED!

8-)
Turrican
 
Posts: 23
Joined: August 11th, 2011, 11:50 pm


Return to ActionScript 3.0