Skip to main content
miquael
Inspiring
June 11, 2008
Answered

How to access vars?

  • June 11, 2008
  • 1 reply
  • 417 views
I have two separate classes that need to communicate with each other. In most cases, seems like this would be very straight forward.

I have a "Pointer" class that represents a visual object on the screen. The Node class has a function that is supposed to make the Pointer object invisible.

public function displayPointer(mode:Boolean) {
var rPointer:DisplayObject = app.container.getChildByName("pointer");
trace (app.container.getChildByName("pointer")); // returns [object Pointer]
trace (rPointer.visible); // returns true
rPointer.hide = mode;
trace (rPointer.visible); // returns false
}

Yet this produced the following error:

1119: Access of possibly undefined property hide through a reference with static type flash.display:DisplayObject

I can use rPointer.visible = mode and that would work, but I need to adjust the "hide" as this variable is key to a more dynamic process involved with the visibility of the Pointer.

"Hide" is instantiated public in the class:

public var hide:Boolean;

So how can I access it?

(please help!)


This topic has been closed for replies.
Correct answer Newsgroup_User
getChildByName returns a DisplayObject, which does not have a hide member.
Just cast the object to a "Pointer".

var rPointer:Pointer= app.container.getChildByName("pointer") as Pointer;

1 reply

Newsgroup_UserCorrect answer
Inspiring
June 11, 2008
getChildByName returns a DisplayObject, which does not have a hide member.
Just cast the object to a "Pointer".

var rPointer:Pointer= app.container.getChildByName("pointer") as Pointer;

miquael
miquaelAuthor
Inspiring
June 12, 2008
Ah, of course. That works!

Thanks so much!