avm1: `button.enabled = undefined` doesn't disable the button

This commit is contained in:
Toad06 2023-04-28 12:21:00 +02:00 committed by relrelb
parent 822c845d83
commit 86c27078d3
7 changed files with 141 additions and 2 deletions

View File

@ -67,6 +67,7 @@ fn enabled<'gc>(
this: Avm1Button<'gc>,
_activation: &mut Activation<'_, 'gc>,
) -> Result<Value<'gc>, Error<'gc>> {
// TODO: This property should return the value set by the user.
Ok(this.enabled().into())
}
@ -75,7 +76,11 @@ fn set_enabled<'gc>(
activation: &mut Activation<'_, 'gc>,
value: Value<'gc>,
) -> Result<(), Error<'gc>> {
let enabled = value.as_bool(activation.swf_version());
let enabled = if matches!(value, Value::Undefined) {
true
} else {
value.as_bool(activation.swf_version())
};
this.set_enabled(&mut activation.context, enabled);
Ok(())
}

View File

@ -1413,6 +1413,7 @@ fn enabled<'gc>(
this: MovieClip<'gc>,
_activation: &mut Activation<'_, 'gc>,
) -> Result<Value<'gc>, Error<'gc>> {
// TODO: This property should return the value set by the user.
Ok(this.enabled().into())
}
@ -1421,7 +1422,11 @@ fn set_enabled<'gc>(
activation: &mut Activation<'_, 'gc>,
value: Value<'gc>,
) -> Result<(), Error<'gc>> {
let enabled = value.as_bool(activation.swf_version());
let enabled = if matches!(value, Value::Undefined) {
true
} else {
value.as_bool(activation.swf_version())
};
this.set_enabled(&mut activation.context, enabled);
Ok(())
}

View File

@ -0,0 +1,45 @@
[
{
"type": "MouseMove",
"pos": [100.0, 100.0]
},
{
"type": "Wait"
},
{
"type": "Wait"
},
{
"type": "MouseDown",
"pos": [100.0, 100.0],
"btn": "Left"
},
{
"type": "Wait"
},
{
"type": "Wait"
},
{
"type": "MouseUp",
"pos": [100.0, 100.0],
"btn": "Left"
},
{
"type": "Wait"
},
{
"type": "Wait"
},
{
"type": "MouseDown",
"pos": [100.0, 100.0],
"btn": "Left"
},
{
"type": "Wait"
},
{
"type": "Wait"
}
]

View File

@ -0,0 +1,21 @@
Step 1: rollOver
MovieClip.prototype.hasOwnProperty('enabled'): true
'enabled' in button: true
button.enabled: true
// button.enabled = undefined
'enabled' in button: true
`button.enabled` is now a falsy value.
`button.enabled` is undefined.
Step 2: press
'enabled' in button: true
`button.enabled` is still a falsy value.
`button.enabled` is still undefined.
Step 3: release
// delete button.enabled
'enabled' in button: true
`button.enabled` is now true.
Step 4: press

View File

@ -0,0 +1,61 @@
// Source code for the `rollOver` event.
// Other events just do `buttonAction("event_name");`.
if(_root.step === undefined) {
_root.step = 1;
_root.enabledInButton = function() {
for(var i in _root.doin) {
if(i === "enabled") { return true; }
}
return false;
};
_root.buttonAction = function(event) {
trace("Step " + step + ": " + event);
var button = _root.doin;
switch(step) {
case 1:
// The mouse moved inside of the button area, this triggers the rollOver event.
trace("MovieClip.prototype.hasOwnProperty('enabled'): " + MovieClip.prototype.hasOwnProperty("enabled"));
trace("'enabled' in button: " + enabledInButton());
trace("button.enabled: " + button.enabled);
button.enabled = false;
button.enabled = undefined;
trace("// button.enabled = undefined");
trace("'enabled' in button: " + enabledInButton());
if(!button.enabled) {
trace("`button.enabled` is now a falsy value.");
if(button.enabled === undefined) {
trace("`button.enabled` is undefined.");
}
}
break;
case 2:
// The mouse left button was pressed, this triggers the press event.
trace("'enabled' in button: " + enabledInButton());
if(!button.enabled) {
trace("`button.enabled` is still a falsy value.");
if(button.enabled === undefined) {
trace("`button.enabled` is still undefined.");
}
}
break;
case 3:
// The mouse left button was released, this triggers the release event.
button.enabled = false;
delete button.enabled;
trace("// delete button.enabled");
trace("'enabled' in button: " + enabledInButton());
if(button.enabled === true) {
trace("`button.enabled` is now true.");
}
break;
case 4:
// The mouse left button was pressed, this triggers the press event.
break;
}
trace("");
step++;
};
}
buttonAction("rollOver");

View File

@ -0,0 +1,2 @@
num_frames = 20
ignore = true