» Are you looking for FLV Player?

Hello, _targetInstanceName!

28 October 2003 | filed under flash | no comments

Yesterday I was raving on the non-functioning of good ol’ _targetInstanceName in Flash MX 2004. Some hours after posting, I received a email from Macromedian Vera Fleischer in which she promised to ask around at the Components QA Engineers to see if they have a solution. Guess what: they do!

The solution is pretty straightforward. It’s just something you need to know: use a getter/setter pair instead of a public variable named _targetInstanceName. In my previous post, I showed the following (failing) code:

[as]class DropMe extends MovieClip {
// ….
[Inspectable(name="target")]
public var _targetInstanceName:String;
// …
}[/as]

Instead, the solution I received from the Components QA Enigneers through Vera is as follows:

[as]class DropMe extends MovieClip
{
public var target:MovieClip;
function DropMe() {};

[Inspectable(_targetInstanceName=""]
function get _targetInstanceName() {
return target;
}

function set _targetInstanceName(t) {
target = _parent[t];
}
}[/as]

As you can see, the public variable named _targetInstanceName is gone and replaced by a getter/setter pair with the same name. Integrating this tip into my original class code, results in the folowing:

[as]class DropMe extends MovieClip {

// version and identification
public var version:String = “1.1.0.0″;
public var className:String = “DropMe”;

public var enabled:Boolean;
public var target:MovieClip;
private var type:String;

// constructor
function DropMe() {
type = typeof target;
if (type “movieclip” || type “object”)
{
trace(”attached to ‘” + target._name + “‘”);
this._visible = false;
enabled = true;
}
else
{
trace(”no target specified!”);
enabled = false;
};
}

// defining a getter function for _targetInstanceName
[Inspectable(_targetInstanceName=""]
function get _targetInstanceName():MovieClip {
return target;
}

// defining a setter function for _targetInstanceName
function set _targetInstanceName( _t:MovieClip ):Void {
target = _parent[_t];
}
}[/as]

Big kudos to Vera! _targetInstanceName is alive and kicking, on to converting my existing components!

 

Leave a Reply