[Flashcoders] Getter/Setter behaviour question

2006-06-30 Thread Derek Vadneau
I checked the archives and Googled variations of this issue but I couldn't 
find anything specific to this issue.

I created a component that contains some inspectable properties, which are 
actually getters and setters. I simplified the class to demonstrate the 
issue.

The inpectable prop is an array to let you specify paths to movieclips. 
Because the array is made up of strings, the setter function is supposed 
to run through the array and eval the strings. However, the setter is only 
called once, and it's passed an empty array, even though there is a 
default and the component properties panel contains data.

Here is the class:

class MyClass
{
private var _scrollTargets:Array;

function MyClass()
{
init();
}

public function init():Void
{
trace('init: '+_scrollTargets);
}

[Inspectable(type=Array,defaultValue=_level0)]
public function set scrollTargets(t:Array)
{
trace('set: '+t);

_scrollTargets = new Array();
}
public function get scrollTargets():Array
{
trace('get: '+_scrollTargets);

return _scrollTargets;
}
}

The array in the component properties panel is _level5, just so it's 
different from the default _level0.

In the Output panel I get:
set:
get:
get:
init: _level5

What gives?

The setter is only called once but somehow the private property is set to 
contain the value(s) I enter.

In the setter, if I don't make _scrollTargets = new Array(), then the 
trace on the init is undefined, as I would expect.

How is the property being set without going through the setter? The 
property being set isn't the same name as the getter/setter (it has an 
underscore) so how is it being set?

I realize I can do this a different way, so I'm not looking for 
alternatives, unless I'm doing something incorrectly, in which case please 
let me know.

TIA,

Derek Vadneau


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Getter/Setter behaviour question [SOLVED]

2006-06-30 Thread Derek Vadneau
For anyone interested:

I figured something out and remember reading something about this, 
although I can't find a link at the moment.

The getter is setting the property. The setter is ignored, and in fact 
there doesn't need to be a setter, and the private property is set.

Example: (the same as my previous code except with the set function 
commented out)

class MyClass
{
private var _scrollTargets:Array = new Array();

function MyClass()
{
init();
}

public function init():Void
{
trace('init: '+_scrollTargets);
}

[Inspectable(type=Array,defaultValue=_level0)]
/*
public function set scrollTargets(t:Array)
{
trace('set: '+t);
}
*/
public function get scrollTargets():Array
{
trace('get: '+_scrollTargets);

return _scrollTargets;
}
}

This traces:
get:
init: _level5

Mystery solved. Dumb, but at least it can be explained.


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com