Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement AVM1 loadVariables

Bonus: rudimentary support for loadMovie, too. Fleshed out in follow-up patches.
  • Loading branch information...
commit 27b97f3bca9df77e093132a61695f7cba83cb6cc 1 parent 1215529
Till Schneidereit tschneidereit authored
26 src/avm1/interpreter.js
View
@@ -943,21 +943,21 @@ function interpretActions(actionsData, scopeContainer,
break;
case 0x9A: // ActionGetURL2
flags = stream.readUI8();
- var httpMethod;
- switch ((flags >> 6) & 3) {
- case 1:
- httpMethod = 'GET';
- break;
- case 2:
- httpMethod = 'POST';
- break;
- }
- var loadMethod = !!(flags & 2) ?
- (!!(flags & 1) ? _global.loadVariables : _global.loadMovie) :
- (!!(flags & 1) ? _global.loadVariablesNum : _global.loadMovieNum);
target = stack.pop();
var url = stack.pop();
- loadMethod.call(_global, url, target, httpMethod);
+ var sendVarsMethod;
+ if (flags & 1) {
+ sendVarsMethod = 'GET';
+ } else if (flags & 2) {
+ sendVarsMethod = 'POST';
+ }
+ var loadTargetFlag = flags & 1 << 6;
+ var loadVariablesFlag = flags & 1 << 7;
+ if (loadVariablesFlag) {
+ _global.loadVariables(url, target, sendVarsMethod);
+ } else {
+ _global.loadMovie(url, target, sendVarsMethod);
+ }
break;
case 0x9F: // ActionGotoFrame2
flags = stream.readUI8();
25 src/avm1lib/AS2Globals.as
View
@@ -17,12 +17,15 @@
*/
package avm1lib {
import flash.display.Loader;
+import flash.events.Event;
import flash.external.ExternalInterface;
import flash.geom.ColorTransform;
import flash.geom.Rectangle;
import flash.media.Sound;
import flash.media.SoundMixer;
import flash.net.SharedObject;
+import flash.net.URLLoader;
+import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.system.Capabilities;
@@ -172,15 +175,21 @@ public dynamic class AS2Globals {
}
loader.load(request);
}
- public function loadVariables(url, target, method) {
+ public function loadVariables(url: String, target: Object, method: String = ''): void {
var nativeTarget = AS2Utils.resolveTarget(target);
- // flash.display.Loader, flash.net.URLLoader
- notImplemented('AS2Globals.loadVariables');
- }
- public function loadVariablesNum(url, level, method) {
- var nativeTarget = AS2Utils.resolveLevel(level);
- // flash.display.Loader, flash.net.URLLoader
- notImplemented('AS2Globals.loadVariablesNum');
+ var request = new URLRequest(url);
+ if (method) {
+ request.method = method;
+ }
+ var loader: URLLoader = new URLLoader(request);
+ loader.dataFormat = URLLoaderDataFormat.VARIABLES;
+ function completeHandler(event: Event): void {
+ loader.removeEventListener(Event.COMPLETE, completeHandler);
+ for (var key: String in loader.data) {
+ nativeTarget[key] = loader.data[key];
+ }
+ }
+ loader.addEventListener(Event.COMPLETE, completeHandler);
}
public function mbchr(number) {
return String.fromCharCode(number);
BIN  src/avm2/generated/avm1lib/avm1lib.abc
View
Binary file not shown
BIN  test/swfs/avm1/loadvariables/loadvariables.fla
View
Binary file not shown
BIN  test/swfs/avm1/loadvariables/loadvariables.swf
View
Binary file not shown
7 test/swfs/avm1/loadvariables/loadvariables.swf.trace
View
@@ -0,0 +1,7 @@
+loadVariables completed. Loaded the following vars:
+varsLoaded=1
+
+escaped=with&amp;amp;
+spacedvalue=multi word
+spaced var=value
+foo=bar
1  test/swfs/avm1/loadvariables/loadvariables.txt
View
@@ -0,0 +1 @@
+foo=bar&spaced+var=value&spacedvalue=multi+word&escaped=with%26amp%3Bamp%3B&varsLoaded=1
7 test/test_manifest.json
View
@@ -330,5 +330,12 @@
"swfs/avm1/settimeout/settimeout.swf"
],
"type": "stas"
+ },
+ { "id": "avm1 loadVariables trace",
+ "stas": "swfs/trace.stas",
+ "filenames": [
+ "swfs/avm1/loadvariables/loadvariables.swf"
+ ],
+ "type": "stas"
}
]
Please sign in to comment.
Something went wrong with that request. Please try again.