|
|||
|
I'd like to create a reusable file reader in SWFKit Pro 2.0. This would be callable from Flash MX 2004. I'd like to allow multiple calls from Flash to load the file and not depend on a prior call being completed (asynchronous).
The problem I'm having is I'm using the Object.watch function in Flash to run the function that happens when the data is loaded. Here is my code so far. The problem arises when the _root.dmCommunications object gets rewritten before the old data had a chance to be retreived: In Flash attached to a global object: Code:
_global.dataManager.getVarDataFromFile = function(vPath, vFile, vFunctionToCall) {
_root.dmCommunications = new Object();
_root.dmCommunications.commString = new String();
_root.dmCommunications.processInfo = new Object();
_root.dmCommunications.processInfo.processString = new String();
_root.dmCommunications.processInfo.processFunction = vFunctionToCall;
_root.dmCommunications.watch("commString", dm.varDataReceived, _root.dmCommunications.processInfo);
fscommand("FFish_Eval", "readData(\"_root.dmCommunications.commString\",\""+vPath+"\",\""+vFile+"\")");
};
Code:
function readData(vFlashString, vPath, vFileName) {
var vRet = "undefined";
if (vPath == undefined | vPath == "<appDir>" ) {
vPath = getAppDir();
}
var vFile = vPath + "\\" + vFileName;
var vFileStreamObj = new FileStream(vFile, "r");
if (vFileStreamObj != undefined) {
vRet = vFileStreamObj.readString();
vFileStreamObj.close();
}
FlashPlayer.setVariable(vFlashString,vRet);
}
Code:
_global.dataManager.getVarDataFromFile(vPath, vFileName, _global.userManger.setupUserFile); Code:
_global.dataManager.getVarDataFromFile(vPath2, vFileName2, _global.userManger.setupMenuData); _________________________________________________ I think I'm heading down the wrong path here and there is a better technique not using the _root.dmCommunications object to watch for SWFKit communications... any ideas? Thanks, Steve |
|
|||
|
You can use the property of an object to watch for swfkit communication:
in action script Code:
function MyObject()
{
this._prop = null;
this.addProperty("myProp", this.getMyProp, this.setMyProp);
}
MyObject.prototype.getMyProp= function()
{
return this._prop;
}
MyObject.prototype.setMyProp= function(prop)
{
this._prop = prop;
//...
//do something
}
myObj = new MyObject;
Code:
//This will call the "MyObject.setMyProp" method in actionscript
FlashPlayer.setVariable("myObj.myProp", "somevalue");
|
|
|||
|
I'm not sure how the object property reponse applies. If it does, please explain.
The problem is not being notified of the property being changed - it's that one call immediately following another call to the same SWFKit function causes the second call to receive the first call's data. I'm trying to come up with a way to thread the calls to SWFKit to read a file so that one call doesn't have to complete before aoother can be made. Similar to retreiving objects displayed in a web page... you might have 4 simultaneous requests for objects... 2 images, one frame text, one plugin. All requested at the same time but arriving on the page in undeterminable orders. Thanks, Steve |
|
|||
|
All of your calls are using the same object "_root.dmCommunications", when the data of the first call returns the "_root.dmCommunications" object notifies the second call.
To resolve the problem, you should assign an unique watching object for each call. If you set the value of a property of an object by using the setVariable method in swfkit, the "set" method of the property of the object in action script will be called. So you can notify an object in actionscript from within swfkit by setting one of its properties. |
![]() |
Was this information helpful? Yes No
| Thread Tools | |
| Display Modes | |
|
|