Menu

[r5]: / trunk / getAS3Vars / src / getAS3Vars.as  Maximize  Restore  History

Download this file

187 lines (165 with data), 6.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/****************************************************************************
* ADOBE SYSTEMS INCORPORATED
* Copyright 2012 Adobe Systems Incorporated and it’s licensors
* All Rights Reserved.
*
* NOTICE: Adobe permits you to use, modify, and distribute this file
* in accordance with the terms of the license agreement accompanying it.
* ****************************************************************************/
package {
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.IEventDispatcher;
import flash.events.IOErrorEvent;
import flash.external.ExternalInterface;
import flash.net.URLRequest;
import ParamHandlers.ObjectParser;
/**
* This is used by the AS3Introspector to wrap a remote SWF so that the data can be retrieved via cross-scripting.
*/
public class getAS3Vars extends Sprite
{
private var as3Display:Loader;
private var sUrl:String;
/**
* Constructor
* Registers the callback functions for the HTML to set up the proxy.
*/
public function getAS3Vars()
{
ExternalInterface.addCallback("as3fetchVar",as3fetchVar);
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
var fVars:String;
for (var keyStr:String in paramObj) {
if (keyStr == "swfurl") {
this.sUrl = paramObj[keyStr];
} else {
if (fVars == null) {
fVars = paramObj[keyStr];
} else {
fVars += "&" + paramObj[keyStr];
}
}
}
this.as3Display = new Loader();
configureListeners(this.as3Display.contentLoaderInfo);
var loadStr:String = this.sUrl;
if (fVars != null && fVars.length > 0) {
loadStr += "?" + fVars;
}
this.as3Display.load(new URLRequest(loadStr));
addChild(this.as3Display);
}
/**
* @private
* Registers listeners (IO_ERROR and COMPLETE) to the IEventDispatcher of the Loader.
*/
private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
}
/**
* @private
* The IOError Handler will dump the error message to the surrounding HTML to be passed back to Flash Analyzer
*
* @param event The IOErrorEvent from the SWF loader.
*/
private function ioErrorHandler(event:IOErrorEvent):void {
ExternalInterface.call("sendMessage","ioErrorHandler: ",event.toString());
}
/**
* @private
* The complete handler which tells Flash Analyzer that the call was a success by sending a message to the surrounding HTML.
*
* @param event The complete event from the SWF Loader.
*/
private function completeHandler(event:Event):void {
ExternalInterface.call("sendMessage","Success: ","SWF is Loaded");
}
/**
* @private
* This function is registered with the HTML as a callback to be used when a value needs to be retrieved, assigned or called as a functoin.
*
* TODO: The paramString needs to be converted to XML.
*
* @param varName The string containing the variable name
* @param action The action to be performed on the object ("call","assign")
* @param paramString The arguments to pass to the function (default null)
* @return The string representing the variable or error.
*/
private function as3fetchVar(varName:String,action:String,paramString:String = null):String {
if (varName == null || varName == "") {
return("Please enter a value to fetch!");
} else if (action == null || action == "") {
return("Please send an action!");
}
var params:Array;
var args:Array;
if (paramString != null && paramString.length > 0) {
params = new Array;
args = paramString.split("||||||");
for each (var paramVar:String in args) {
var temp:Array = paramVar.split("&&&&&&");
if (temp[0] == "int") {
params.push(int(temp[1]));
} else if (temp[0] == "null") {
params.push(null);
} else if (temp[0] == "Array") {
params.push (temp[1].split(","));
} else if (temp[0] == "Number") {
params.push (Number(temp[1]));
} else if (temp[0] == "XML") {
params.push(new XML(temp[1]));
} else if (temp[0] == "uint") {
params.push(uint(Number(temp[1])));
} else if (temp[0] == "Boolean") {
var b:Boolean = false;
if (temp[0] == "true" || temp[0] == "1") {
b = true;
}
params.push(b);
} else {
params.push(temp[1]);
}
}
}
var chunks:Array = varName.split(".");
var varArray:DisplayObject = this.as3Display.content;
var tempArray:Array = new Array();
var dumbFlag:int = -1;
try {
for each (var i:* in chunks) {
if (dumbFlag == -1) {
if (action == "call" && chunks.length == 1) {
args = new Array(1);
tempArray.push(varArray[i].apply(varArray,params));
} else if (action == "assign" && chunks.length == 1) {
varArray[i] = params[0];
return ("Value Assigned");
} else {
tempArray.push(varArray[i]);
}
} else if ((chunks.length == dumbFlag + 2) && action == "call") {
tempArray.push(tempArray[dumbFlag][i].apply(tempArray[dumbFlag],params));
} else if ((chunks.length == dumbFlag + 2) && action == "assign") {
tempArray[dumbFlag][i] = params[0];
return("Value Assigned");
} else {
tempArray.push(tempArray[dumbFlag][i]);
}
dumbFlag++;
}
} catch (e:Error) {
return(e.name + ": " + e.message);
}
var varData:* = tempArray.pop();
var outputData:String = "";
var oParser:ObjectParser = new ObjectParser();
outputData += oParser.valueToString(i,varData);
return(outputData);
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.