Language: ChineseGermanSpanishFrenchDutchItalianRussian
123 Flash Chat Forums

Go Back   TOPCMM Community > SWFKit > SWFKit Support

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-31-2005, 01:03 PM
Junior Member
 
Join Date: Jun 2003
Posts: 29
Default Reusable file reader

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+"\")");
};
In SWFKit:

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);
}
The function is called in Flash by:

Code:
_global.dataManager.getVarDataFromFile(vPath, vFileName, _global.userManger.setupUserFile);
If another call gets made immediately following the last like:
Code:
_global.dataManager.getVarDataFromFile(vPath2, vFileName2, _global.userManger.setupMenuData);
the _global.userManger.setupMenuData function receives the content loaded by the first function.

_________________________________________________
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
Reply With Quote
  #2 (permalink)  
Old 02-01-2005, 11:08 AM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re:Reusable file reader

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;
in swfkit

Code:
//This will call the "MyObject.setMyProp" method in actionscript
FlashPlayer.setVariable("myObj.myProp", "somevalue");
Reply With Quote
  #3 (permalink)  
Old 02-01-2005, 02:29 PM
Junior Member
 
Join Date: Jun 2003
Posts: 29
Default Re:Reusable file reader

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
Reply With Quote
  #4 (permalink)  
Old 02-02-2005, 10:43 AM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re:Reusable file reader

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.
Reply With Quote
Reply

Was this information helpful?    Yes No



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 07:41 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.