Hello, _targetInstanceName!
Tuesday 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]
- download source files.
Big kudos to Vera! _targetInstanceName is alive and kicking, on to converting my existing components!
« previously: Goodbye, _targetInstanceName? next: Google Deskbar »
Leave a Reply
Recent Articles
- New bike
- FLV Player 2.0.25 released
- No custom headers for Flash file upload. Why?
- Building AIR with FDT
- Adobe MAX 2007
- FLV Player 2.0 released
- The new Photoshop logo
- mProjector WindowResizer class
Advertisement
Categories
- Art & Design (4)
- Flash (37)
- FLV Player (9)
- Software (16)
- User Experience Design (3)
- Various (8)
- Work (6)