Skip to content

Commit

Permalink
Implement AS2 TextField.variable accessor
Browse files Browse the repository at this point in the history
Lets the ad from mozilla#471 get ever so slightly further
  • Loading branch information
tschneidereit committed Oct 31, 2013
1 parent 201b285 commit fcec5e9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 39 deletions.
6 changes: 3 additions & 3 deletions src/avm2/generated/avm1lib/AS2TextField.as
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ package avm1lib {

public function get _url() { return this._as3Object.loaderInfo.url; }

public function get variable() { throw 'Not implemented: get$variable'; }
public function set variable(value) { throw 'Not implemented: set$variable'; }
public native function get variable();
public native function set variable(value);

public function get _visible() { return this._as3Object.visible; }
public function set _visible(value) { this._as3Object.visible = +value !== 0; }
Expand Down Expand Up @@ -194,4 +194,4 @@ package avm1lib {
AS2Utils.addEventHandlerProxy(prototype, 'onSetFocus', 'focusIn', function(e) { return [e.relatedObject]; });
}
}
}
}
Binary file modified src/avm2/generated/avm1lib/avm1lib.abc
Binary file not shown.
49 changes: 45 additions & 4 deletions src/flash/avm1lib/AS2TextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,62 @@ var AS2TextFieldDefinition = (function () {
__class__: 'avm1lib.AS2TextField',

initialize: function () {
this._variable = '';
},
};

var desc = Object.getOwnPropertyDescriptor;

def.__glue__ = {
native: {
instance: {
variable: {
get: function() {
return this._variable;
},
set: function(name) {
if (name === this._variable) {
return;
}
this._variable = name;
var instance = this.$nativeObject;
var hasPath = name.indexOf('.') >= 0 || name.indexOf(':') >= 0;
var clip;
if (hasPath) {
var targetPath = name.split(/[.:\/]/g);
name = targetPath.pop();
if (targetPath[0] == '_root' || targetPath[0] === '') {
clip = instance.root._getAS2Object();
targetPath.shift();
if (targetPath[0] === '') {
targetPath.shift();
}
} else {
clip = instance._parent._getAS2Object();
}
while (targetPath.length > 0) {
var childName = targetPath.shift();
clip = clip.asGetPublicProperty(childName) || clip[childName];
if (!clip) {
throw new Error('Cannot find ' + childName + ' variable');
}
}
} else {
clip = instance._parent._getAS2Object();
}
if (!clip.asHasProperty(undefined, name, 0)) {
clip.asSetPublicProperty(name, instance.text);
}
instance._addEventListener('advanceFrame', function() {
instance.text = '' + clip.asGetPublicProperty(name);
});
}
},
_as3Object: {
get: function () {
return this.$nativeObject;
}
},
_init: function init(nativeTextField) {
Object.defineProperty(this, '$nativeObject', { value: nativeTextField });
Object.defineProperty(this, '$nativeObject', {value: nativeTextField});
nativeTextField.$as2Object = this;
initDefaultListeners(this);
},
Expand All @@ -47,4 +88,4 @@ var AS2TextFieldDefinition = (function () {
};

return def;
}).call(this);
}).call(this);
34 changes: 2 additions & 32 deletions src/flash/display/Sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,38 +253,8 @@ var SpriteDefinition = (function () {
var symbolProps = instance.symbol;

if (symbolProps && symbolProps.variableName) {
var variableName = symbolProps.variableName;
var hasPath = variableName.lastIndexOf('.') >= 0 ||
variableName.lastIndexOf(':') >= 0;
var clip;
if (hasPath) {
var targetPath = variableName.split(/[.:\/]/g);
variableName = targetPath.pop();
if (targetPath[0] == '_root' || targetPath[0] === '') {
clip = this.root._getAS2Object();
targetPath.shift();
if (targetPath[0] === '') {
targetPath.shift();
}
} else {
clip = this._getAS2Object();
}
while (targetPath.length > 0) {
var childName = targetPath.shift();
clip = clip.asGetPublicProperty(childName) || clip[childName];
if (!clip) {
throw new Error('Cannot find ' + childName + ' variable');
}
}
} else {
clip = this._getAS2Object();
}
if (!clip.asHasProperty(undefined, variableName, 0)) {
clip.asSetPublicProperty(variableName, instance.text);
}
instance._addEventListener('advanceFrame', function() {
instance.text = '' + clip.asGetPublicProperty(variableName);
});
instance._getAS2Object().asSetPublicProperty('variable',
symbolProps.variableName);
}

if (events) {
Expand Down

0 comments on commit fcec5e9

Please sign in to comment.