PDA

View Full Version : Passing component buttons to classes


Chewie
01-18-2006, 10:57 AM
I want to pass a component button as an instance parameter to a class, so that I can get the buttons properties in the class.

Here is the class
class Temp extends MovieClip {
var button:Button;
public function Temp(_button:Button) {
button = _button;
trace(button) // traces _level0.cbtButton
trace(button._height) // traces 0
//trace(button.height) // ERROR : There is no property with the name 'height'.
}
}

And here is the fla script
this.createObject("Button", "cbtButton", (1),{_height:30});
instance = new Temp(cbtButton)
trace(instance.button) // traces _level0.cbtButton
trace(instance.button.height) // traces 30
trace(cbtButton.height) // traces 30
trace(instance.button._height) // traces 0
trace(cbtButton._height) // traces 0

Now it seems that to get the height property of a component button, I need to use height, and not _height, although it is initially set using _height.

The problem is if I try to use height in the class, I get the error there is no property with the name height. I can use _height in the class but it returns 0.

Can anyone help me out here.

Thanks

Chewie
01-21-2006, 06:23 PM
Anybody ?

I ended up passing variables with the buttons width and height to the class to get round the problem, but I would be interested to find out why the actual values for the buttons are misreported