The LoadVars.load Method Is An Asynchronous Action? Race Conditions?
I am trying to determine if a file exists on a server using the LoadVars.load method and checking for "success". I believe I am having an issue because I am actually using a 'for loop' to run through the file names while calling the '.load' method every iteration. However, every call seems to fork and do it's own thing while the loop continues.
This does actually work and it does find the file, but I don't want to make all these uneeded calls and more importantly...I am not even sure if there is a race condition and the variable I am depending on to be set further down in the code will be ready.
Is there any way to have my 'for loop' wait for the '.load' method to complete before continuing with the iterations? Maybe a while loop that checks '.isLoaded' or a more suitable method?
CODE:
PHP Code:
var vidExtensions:Array = new Array; //These are all the possible movie file extensions that could be there vidExtensions = [".3gp", ".3gp3", ".mpg", ".avi", ".mp4", ".mqv", ".mov"]; //Create the URL except the extension var testPath:String = new String(); testPath = imgThumbPath.substr(0, imgThumbPath.indexOf("tn_")); testPath += imgThumbPath.slice(testPath.length + 3, imgThumbPath.length - 4); var fileExists = new LoadVars(); fileExists.onLoad=function(success) { if(success){ trace("SUCCESS!"); //We have found the correct file myLink = unescape(""+sendPath); } else{ trace("FAIL"); } } //Loop through all possible movie extensions for(var i=0;i<vidExtensions.length;i++){ var sendPath = testPath + vidExtensions[i]; //Check if file exists fileExists.load(sendPath);
}
FlashKit > Flash Help > Flash ActionScript
Posted on: 04-17-2007, 05:28 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
LoadVars.send() Asynchronous?
Does anybody know if LoadVars.send() is asynchronous? I can't find it documented anywhere. sendAndLoad() is asynchronous, but that's (at least) because it has a load() method in there. I assume that send() is asynchronous, but it returns a 'success' value. At first glance, I'd assume it couldn't return a success value if it were asynchronous, but at second glance it might be that the success value is simply whether or not the variables were sent or not. Anybody know if send() is asynchronous?
If it is asynchronous, I guess I'd have to use sendAndLoad() in order to find out when the variables went through.
Help With Asynchronous Action
Hi People,
I having trouble coding the following:
- method "A" calls method "B" from another Class;
- method "B" initiates an asynchronous action(onEnterFrame verification);
- When the event initiated by method "B" is finished,method "B" should return a value to method "A" perform a logic comparison;
My problem is:
-----------------
how do I pass the value from the onEnterFrame event(when finished)
to its calling method(method "B" return statement) ?
How do I return the value from function "B" to function "A" correctly ? ( it always return "undefined" because function "B" calls an asynchronous action.
Thanks everybody
Race Game Using Action Script
Hello, I am trying to develop a simple race game, using almost only Action script. I am in a little bit of trouble because I haven't a lot of experience with this language.
One of the problems is:
I need some trees a the border of the road; I'm doing like this:
CODEduration=1000;
function createtree():Void {
if (i<20) {
attachMovie("tree", "tree"+i, i);
this["tree"+i].dir = Math.floor(Math.random()*2);
i++;
}
}
intervalId = setInterval(this, "createtree", duration);
Swf Load Conditions Help.
I am a creaive designer for a small company. I need some help with some conditional action script for a site that I will be showing a big client next week.
I am loading swfs into empty MC in my index swf. My question is, is there a way to tell my content swf (or target MC) to load only after the buttons swf & backrounds swf are completed?
When all the animation occurs at once, my concern is it will lack in smoothness.
Any help is greatly appreciated, & thanks
-pk
LoadVars Has A Dud Method
I've spent way too much time trying to get the loadVars.send method to work, it seems it will only pass vars if I post it to a new window, any attempt to send vars with out opening a new browser window did not work!
I was able to finally send vars using the sendAndLoad method, it send in the backgroud fine, then I just take the vars it returns and delete them, this is a crappy work around, has anyone else had this problem
MyVars.send("http://www..."); // does not send vars
myVars.send("http://www...", "POST") // no good eighter
myVars.send("http://www...","_blank", "POST") // works but opens a new window?
LoadVars Method
Hi all
I'm trying to use the LoadVars method to load some text from a file.txt into a textbox
textbox has variable 'text' attached to it
textfile has: &text=blah blah...
here's my code:
onClipEvent (load) {
// create loadVars object
myData = new LoadVars();
// load data
myData.load("file.txt");
}
I can output the text using trace, but i can't get the text to load into the textbox (?)
* this is what I used before (and it works):
LoadVariables("file.txt", this);
but I want to use the newer method
any help is welcome
LoadVars POST Method Not Working?
I'm trying to use the POST method of the LoadVars object, but it don't seems to work
Code:
var source = '<dock><height>25</height><cube><x>0</x><y>0</y></cube></dock>';
var dock_lv = new LoadVars();
dock_lv.dockXml = source;
dock_lv.send("http://localhost/CanDock/setDock.asp", "_blank", "POST");
It always seems to send it using the GET method. It shouldn't be a problem (it's not confidential data), but it seems there a limit on the amount of caracter I can send using the GET method (I usally used the POST method, so I never experienced this before).
Anyone can help ?
CFK
[F8] LoadVars/PHP Problem - SendAndLoad Method
I'm trying to send variables from a Flash movie to a PHP script and just can't get it to work.
Say I have a LoadVars object called myVars, and I'm assigning variables to it in the following way;
code:
myVars.val1 = value;
myVars.val2 = value;
...and so on. I then attempt to send these values to a PHP script as follows:
code:
myVars.sendAndLoad("myscript.php");
As I understand it, my variables should then be available to the PHP script via the $_POST array, but this isn't working. Does anyone have any ideas?!
Problem With LoadVars LoadAndSend Method
Hi...
I am having a small problem...
I am using the following code to send the text generated in a dynamic text box to myself in an email:
this.submit_btn.onRelease = function() {
var emailResponse:LoadVars = new LoadVars();
emailResponse.onLoad = function(success:Boolean) {
if (success) {
debug_txt.text = "your poem has been submitted";
} else {
debug_txt.text = "there has been an error";
}
};
var email:LoadVars = new LoadVars();
email.recipient = "contact@fourinchesofego.com";
email.subject = "new_ann_coulter_poem";
email.themessage = poem_txt.text;
email.sendAndLoad("
Problem With LoadVars In A Class Method
Hi, this is my first post here.
I have been going totally crazy with this problem since yesterday and I hope someone here can help me with this.
I am writing a custom class called diagram and I have a method called readDiagramTextFile() which reads from a text file (path passed as a parameter to the method) and returns a variable read from the text file. I'm using LoadVars for this. Here is the code for the method:
Code:
function readDiagramTextFile(filePath:String):String{
var diagramLV:LoadVars = new LoadVars();
var returnText:String;
diagramLV.onLoad = function(success:Boolean){
if(success){
returnText = this.variableName;
trace(returnText);
} else {
trace("Error while loading the text.");
}
}
diagramLV.load(filePath);
trace(returnText);
return returnText;
}
I want this method to return the value of the variable from the text file. However it is not working as it should. The onLoad() gets executed after the "return" statement, hence the function ends up returning an empty string.
The first trace (inside the onLoad) returns the text I want but the second trace (above the return) gives "undefined".
Is there any way to make sure the load is complete before I return the value? Is this a problem with scope? It's driving me crazy and I have already spent almost 10 hours trying various things getting this to work!
Any help will be greatly appreciated!
Flash LoadVars.send Method
I'm sending three variables from Flash to a database using the LoadVars.send method. My code to send the variables is:
coordinates.send("coordinates.asp", "post");
Even though there is no '_target' it still opens the results in a new window.
Is there any way to stop it from doing this?
AS1 - LoadVars.send Method Does Not Work In Browser
I am struggling with what appears to be the simplest thing.
Please tell me why my highscores.php file doesn’t open with “?playerscore=5413&playername=Rowan” after it.
When tested in my browser or on my local server, it outputs like this: “http://localhost/GameTest/highscores.php”
When tested from Flash (ctrl+Enter), it works perfectly. My browser opens and displays: “///D:/Work/GameTest/highscores.php?playerscore=5413&playername=Rowan” in the address bar.
What am I missing here?
(Please see attached files)
I am using CS3 but file must be published as v6.
Attached Files
Getting Menu To Load Movie Clips Based On Conditions
Hi all - I'm trying to replicate a cool menu effect I saw on another website; it obviously involves movie clips communicating with one another based on which of them is loaded. You can see the basic effect in action here:
http://www.zerogny.com/zero_gravity_design_group.cfm
And now let me try to explain how I want to adapt it for my project.
What I want is to have four basic buttons - "about us," "portfolio", etc. - to kick off a movie clip that plays beside the button panel. If you press the "about us" button, a movie clip with an animated message "about us" unfolds upon the stage; when you click the "portfolio" button, however, the "about us" animation goes in reverse; when it has completely reversed, then the "portfolio" animation loads onto the stage.
So far, I have figured out how to load four movie clips (plus a fifth, default MC) onto the stage depending on which button is pressed; that's pretty basic stuff, I suppose, although it was hard for a newbie like me (see attachment). Eventually, each of these movie clips will have a "loading" animation that stops at frame 25. At frame 26, the frames are reversed so that, when played, those frames would show the animation "unloading" off the stage. At the current stage of my project, I have only added the "unloading" frames to the second button's action; of course, only the "loading" animation shows, no matter which button is pressed.
To take my movie to the next level, I need help in figuring out how to tell the next button pressed, say "portfolio," to tell the "about us" movie (if that's the one occupying the stage) to play its unloading sequence from frame 26 and then (at frame 52) load the "portfolio" sequence or whichever sequence has been been cued by the user to enter the stage. I know this is an issue involving variables and conditions, but I am such a new newbie I can't figure out how to make this work. I'd surely appreciate any help out there; I know this issue has been dealt with before, as so many menus seem to use the effect I'm after.
Method, Action, Funtion - Exactly What's What ?
Recently I had a misunderstanding due to a lack of actual programming knowledge. Terminology is one of them. Can someone explain the exact diffences between a method, an action and a function ?
Thanks in advance !
How Do You Use LoadVars Object With "sendAndLoad" Method ?
Hey all,
can someone tell me how to use the loadVars object and the sendAndLoad method. It seems straight forward, but i cant get it to work.
I am an experienced object and Flash 5 scripter, but cant quite get the hang of this loadVars object.
I want to send all variables from a movie clip to an asp page and then recieve a variable back from that page, "result=ok" to tell me that my variables have been recieved.
It all works fine in Flash 5 with loadVariables, but i cant use that in Flash MX. Flash MX will NOT send variables using loadVariables.
any help would be greatfuly appreciated.
thanks in advance
gilesb
Load Xml Best Method?
Hi guys.I was wondering which is the best method to load xml: using AS or using XMLConnector + components??
I used the 2nd method and i think it`s loading kinda hard...i mean i have an xmlconnector 1 list and 1 loader for pics and when i click the items on the list the pics apear...but it takes 2-3 sec for them to appear.If i use AS it would be better? Thx in advance
SendAnd Load Method
I want to send variables to a cgi script then after the submission of the form i want to be able to redirect back to my flash move to say thankyou for your submission. I've been told the sendAndLoad method is the go but i'm unsure of the syntax to use it does anyone know?
thanks
Drew
XML Send Or Load Method?
I am trying to set up an online quiz in flash mx with the questions delivered by xml file - so that the client can quickly update them without having to re-write the swf. Can anyone help or suggest any online tutorials that might be of use? Basically the quis is currently set up so you click on a button and a question appears via actionscripting out of the swf
Thanks
M
[F8] Load Variable In Method
hello i want to load the linestyle properties like line size, color etc from external file, i am dummy please help.
dummy.onMouseDown = function() {
if (1) {
this.lineStyle(5,0x006699,100,true,"normal","round ","round",4);
this.moveTo(_xmouse, _ymouse);
this.onMouseMove = function() {
this.lineTo(_xmouse, _ymouse);
updateAfterEvent()
};
this.onMouseUp = function() {
delete this.onMouseMove;
};
}
};
Problems With Load() Method
GRRRRRR.....
Ok, I've got a swf loading into the main swf like this...
var loadOne = new Loader();
container_mc.addChild(loadOne);
loadOne.load(new URLRequest("page1.swf"));
Now a few things that are pissing me off..
How do I talk to the timeline of the new swf I just loaded????
I want to tell it to gotoAndPlay("frame") but I can't figure out how. container_mc.gotoAndPlay("whatever"); doesn't work, neither does container_mc.loadOne or loadOne.goto.....
Also, I have 3 buttons that should replace the loaded movie with a different one. First I tried this:
b1.addEventListener(MouseEvent.CLICK, clickOne);
b2.addEventListener(MouseEvent.CLICK, clickTwo);
b3.addEventListener(MouseEvent.CLICK, clickThree);
function clickOne(event:MouseEvent):void{
loadOne.load(new URLRequest("page1.swf"));
}
function clickTwo(event:MouseEvent):void{
loadOne.load(new URLRequest("page2.swf"));
}
function clickThree(event:MouseEvent):void{
loadOne.load(new URLRequest("page3.swf"));
}
Thinking I could just load something new into the loader that I had already created, but it gave me an error and wouldn't let me do that, so then I tried this:
function clickOne(event:MouseEvent):void{
var loadOne = new Loader();
container.addChild(loadOne);
loadOne.load(new URLRequest("page1.swf"));
}
function clickTwo(event:MouseEvent):void{
var loadTwo = new Loader();
container.addChild(loadTwo);
loadTwo.load(new URLRequest("page2.swf"));
}
function clickThree(event:MouseEvent):void{
var loadThree = new Loader();
container.addChild(loadThree);
loadThree.load(new URLRequest("page3.swf"));
}
And that just loads the new movie on top of the last movie.
Thanks! I've finally just barely started learning as3 and this is my first post, so you might be seeing me a lot from here on out.
Load XML In LoadMovie Method
I defined var image which I use for URL to loading content of XML file.
I dont how can I define it to have var image outside of XML_images.onLoad because this woks:
Code:
var XML_images:XML = new XML();
XML_images.ignoreWhite = true;
XML_images.load("xml/castillo_images.xml");
XML_images.onLoad = function(success) {
if (success) {
rootNode = XML_images.firstChild;
var image:Array = new Array();
image[1] = rootNode.childNodes[1].childNodes[0].childNodes[0];
//image[1] = rootNode.childNodes[1].childNodes[0].childNodes[1];
/*trace("XML_images.firstChild = "+this.firstChild);
trace("XML_images.childNodes.length = "+rootNode.childNodes.length);
trace("rootNode.firstChild.firstChild.firstChild = "+rootNode.firstChild.firstChild.firstChild);
*/
trace("rootNode.childNodes[0].childNodes[0].childNodes[0]= "+rootNode.childNodes[0].childNodes[0].childNodes[0]);
createEmptyMovieClip("image_holder", 1000);
image_holder.loadMovie(image[1]);
trace("image = "+image[0]);
} else {
"NOT loaded!";
}
};
AND THIS NOT WORKS:
Code:
var XML_images:XML = new XML();
XML_images.ignoreWhite = true;
XML_images.load("xml/castillo_images.xml");
XML_images.onLoad = function(success) {
if (success) {
rootNode = XML_images.firstChild;
var image:Array = new Array();
image[1] = rootNode.childNodes[1].childNodes[0].childNodes[0];
//image[1] = rootNode.childNodes[1].childNodes[0].childNodes[1];
/*trace("XML_images.firstChild = "+this.firstChild);
trace("XML_images.childNodes.length = "+rootNode.childNodes.length);
trace("rootNode.firstChild.firstChild.firstChild = "+rootNode.firstChild.firstChild.firstChild);
*/
trace("rootNode.childNodes[0].childNodes[0].childNodes[0]= "+rootNode.childNodes[0].childNodes[0].childNodes[0]);
} else {
"NOT loaded!";
}
};
function firstImage() {
createEmptyMovieClip("image_holder", 1000);
image_holder.loadMovie(image[1]);
trace("image = "+image[0]);
}
OnClipEvent (load) Vs OnLoad Method
i place a mc named ball on the first and unique frame, on the stage
inside it i write:
onClipEvent(load){
trace("hello");
}
and it works as expected...
but what if i don't want to have code in the mc?
i can write on the main timeline, in the first frame:
_root.ball.onLoad = function(){
trace("hello");
};
and it doesn't work, unless the mc ball has some code, and surprisingly, all the code it needs is something like:
//
or even just an extra blank line
why does this happen?
is there another way to solve this?
because this is a simple example... but instead of a ball, i could have fiveHundred!!
Load CSS StyleSheet In Class Method.
Hi,
Im trying to put some css style in textfield of the movieclip throught a class method, but the css style doesnt apply to the textfield. Please, check the code because its a really simple thing, and this is one of those days that simple things doesnt work.
Here is the code.
Code:
dynamic class lib.ContenedorBar {
private var lv:LoadVars;
private var myText:String;
private var myStyle:TextField.StyleSheet;
public function ContenedorBar() {
var _this = this;
this.lv = new LoadVars();
this.myStyle= new TextField.StyleSheet();
this.myTextField.autoSize = true;
this.myTextField.html = true;
this.myTextField.border = true;
this.myStyle.load("xml/bar.css");
this.lv.load("xml/bar.txt");
this.myStyle.onLoad = function(success:Boolean) {
if (success) {
_this.myTextField.styleSheet = this;
}
};
this.lv.onLoad = function(success:Boolean) {
if (success) {
_this.myTextField.htmlText = _this.myText;
}
};
}
}
Method To Load String Of .jpgs?
I'm not sure which method I need to be using to do what I want.
What I'm doing is setting up a photo gallery, I have all my thumbnails saved to a folder with names of thumb01.jpg to thumb21.jpg and all my large photos (what the user sees after they click on the thumbnail) in a separate folder and named large01.jpg to large21.jpg.
I've been reading about arrays, vars, lists ect and I'm not sure which is the best (easiest to understand, and change later) way to accomplish loading the thumbnails on the stage and then the large photo once the thumbnail is clicked.
If someone can advise which method would be the best and someplace I can get information about putting the code together I would appreciate it.
[AS1] .attachMovie Method To Load Images
I am creating a gallery that loads the images from the library. The only method that I managed to do this is by creating movie clips that contain each of those images and then calling those movie clips from the library using the .attachMovie method because this method only works for movie clips and not instances of other library items such as actual images.
Is there anyway in ActionScript to create an instance of an image asset in the library?
Best Method To Add Mp3 Song To Load Fast In MX?
Hello,
I'm a novice designer and have not done alot of sound work in Flash but have a movie I'm working on and I ripped an entire mp3 song and added it to the timeline with some pics and the swf file is 7mb and it take a while to load.
Is there some basic tricks to get this to load fast?
what audio quality format is best?
Thanks,
Michael
Asynchronous XML
Hello all,
I'm having a bit of an XML problem. I'm trying to get my XML to load before the rest of the script executes. The problems is, if I do something like the following, buildCalendar does not execute. Any suggestions?
myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = myOnLoad;
myXML.load("calendar.xml");
function myOnLoad(success) {
if(success) {
trace("Loaded XML");
xmlCreateArray();
} else {
trace("Error - Could not load XML file");
}
}
function xmlCreateArray() {
xmlArrayDate = new Array();
// loop array code here
buildCalendar()
}
function buildCalendar() {
// Prototypes
// calendar code here
trace("Hey there, I'm working.")
)
Load A Numerical Variable With The LoadVar Method
I want to load a numerical var in the movie, but after i load it i cant get incremment, i'm doing something like a counter, that's 'cause i want to load it and make operations with it.
I prove "trace(typeof)" to know the type of the var and the output says that its undefined. How can i define it.
Thanx
How To Load XML File Inside Object Method
Hi,
I am able to load an XML file but now I want to make my code cleaner and I want to do it inside the constructor of an object.
Loading an XML file happens in 2 steps :
1. start the loading by
myXMLdoc.load("example.xml");
2. Flash indicates it has finished loading by calling the myXMLdoc.onLoad() function.
How do I declare/define the onLoad event handler inside a class definition ??
Here is my class code so far (generating an error around the onLoad function) :
I am calling the aSiteXMLDoc.load method in the constructor, and I tried to point the aSiteXMLDoc.onLoad handler to the 'this.load' method... but the compiler doesn't like it this way :-(
Attach Code
class myclasses.site{
var aSiteXMLDoc:XML;
var h1s:Array = new Array();
public function site(aSiteDocFileName:String) {
aSiteXMLDoc = new XML();
aSiteXMLDoc.ignoreWhite = true;
aSiteXMLDoc.onLoad = this.load(success);
aSiteXMLDoc.load(aSiteDocFileName);
}
public function load(success):Void {
if (success) {
var aNode:XMLNode = aSiteXMLDoc.firstChild;
while (aNode != null) {
this.addh1(aNode);
aNode = aNode.nextSibling;
}
}
}
public function addh1(aNode:XMLNode):Void {
var new_h1:myclasses.h1 = new myclasses.h1();
new_h1.title="test title";
new_h1.colorscheme="nice";
h1s.push(new_h1);
}
public function draw():Void {
for (var x:Number=0; x<h1s.length; x++) {
h1s[x].draw();
}
}
}
Loadvar Class Load() Method Problem In IE6 And IE7
Hello all,
I m using Flash Player 8 .In IE6 and IE7 my_LoadVars.load("url") method seems only run once . when I call my_LoadVars.load("url") a second time I get the same data as the first call back , even though i have called url with new data. This doesn't happen in Mozilla.
please help me on this issue.
thanks in advance
Is DuplicateMovieClip() Asynchronous Or Not?
Hello,
I am in my own personal hell trying to wrangle duplicateMovie() into submission. My code is straightforward:
while(i < howmany( {
// stuff
trace("hello from hither");
duplicateMovieClip("seed", "target", depth);
// stuff
i = 1 + i;
}
At frame 1 of the target movie I have:
trace("hello from yonder");
I was expecting the "hither" and "yonder" traces to interleave:
hither
yonder
hither
yonder
hither
yonder
...
Nope. First all the hithers then all the yonders appear. Huh? This implies that duplicateMovie(). Yes or no?
How do I make the traces interleave?
Cheers,
Douglass Turner
email: turner@landmat.com
Is LoadVariables() Asynchronous?
when loadVariables() is called, does it return before loading the variables?
i have the following script:
_root.loadVariables(url,0);
my_text_box = _root.param_from_url;
which doesn't work as expected. The first time the code is executed, nothing happens. The second time the code is executed, the text from the first time appears in the text box. And so on. Any ideas why this is happening?
thanks
Asynchronous Problem
Hi, i'm facing an asynchronous problem: the call to the function "DrawNews" is being executed before the xml is completely loaded into the XML obj... what's the way to deal with it?
/:NewsMenu = new XML();
/:NewsMenu.load("NewsDataSource.asp");
/:NewsMenu.onLoad = DrawNews;
Thanks in advanced,
Maya.
Asynchronous Call
Hi,
how can I make an asynchronous call to a function.
I want to implement a search "thread" which should search.. but the user should still be able to type into the textfield. At the moment it is something like :
search_inputmask.onChanged = function()
{
...
setInterval(sendSearch,300)
...
}
which does not work.
How can I make this call not to stop flash reacting to user inputs?
Any ideas?
Philipp
Asynchronous Loops
I'm trying to use AS to add a series of buttons, and set the onPress property for each one. I've used a loop, but the loop seems to run through before the property is set. My code.
do {
_root.tback.attachMovie("blob", "blob"+f, 100+f);
this["blob"+f]._x = 50*f;
this["blob"+f].onPress = function() {
getURL(f+".htm");
};
f++;
} while (f<4);
So this adds three buttons, correctly positions them, BUT doesn't give them getURL 1.htm, 2.htm and 3.htm but instead gives all 3 getURL ("4.htm").
How can I make sure the correct urls are added before the loop continues?
Asynchronous XML Documents
Hi,
I'm fairly new to Flash and am not sure if Flash can handle the problem I am trying to solve or not, but if so, can someone point me to some examples or place where I can get more information? Many thanks in advance!
Here is what I would like to do...
I have an HTTP server that collects network information and asynchronously sends XML documents to various clients whenever the network environment changes. So far, all of my clients have been written using a combination of Java, HTML, XML, XSL, and JavaScript. I'd like to create a Flash client.
Right now, when a client is started, it opens a socket on the server and sends a special XML document that informs the server that it wants to receive asynchronous data. The server saves this socket and whenever it receives new data, it asynchronously sends an XML document to the client over this socket.
So, my questions are as follows:
Can I use Flash in this manner?
Do I use the same technique of opening a socket on the server to receive asynchronous XML documents or does Flash handle this a different way?
I've written a custom HTTP server using Java. Will my server require any special plugins or code to handle an asynchronous connection to the Flash movie? I'd prefer not to embed proprietary plugins on my server unless I can redistribute my software without paying royalties.
Do you have any examples a Flash app/movie that receives asynchronous XML documents from a server that I can view to get me started with this project?
Thank you very much. Please message me if you need clarification.
As3 + Asynchronous = Annoyance
Hey!
I remember working with AMFPHP in AS2 and arguing with MANY flash developers who praised asynchronous stuff within flash. Granted its a nice way to do things but from a progmatical point of view its a nightmare...
Let me explain my situation and problem a bit more...
I want to use AMFPHP and wrap up the service communication in classes, so its all handled via external .as files, this way to do communication via Flash + PHP i only need to include a package instansiate the given class then send over a service request.
In an ideal world here is how i would imagine it going:
Code:
// I would have an internal default gateway incase you dont want to set one...
var serviceCommunicator:amfService = new amfService(my_gateway);
// Once the objects created, i would call a function "runService(arg1,arg2)" this
// would then ideally do the connection, run the service, then return out an
// object with the data retrieved from the service.
var serviceResult:Object = serviceCommunicator.runService(my_service, my_params);
Now the code above seems fairly logical and easy to use to me, that way you would wrap up alot of the functionality internally in the amfService class and all you need to do is run 2 lines to communicate with PHP...
However due to it being async, when you call run service it has to point the service to 2 return functions one for success one for error, that instantly means that you cant return anything worth while from the runService function as that just sets up the callback functions.
At this point i thought there MUST be a way to get my response without having to make a loader movieclip in flash or having to do some nasty global variables which dump the object when complete.
So im trying to think of ways to do this, i was thinking of maybe making a timer and having a while loop in the runService function to see if it has had a response (good or bad) then return out the relevent data that way. The timer could check a boolean flag internally to see if the operation has completed then return out, however im SURE that flash holds on while statements so i dont think i can do it that way. Then i thought about making an event that fired, but thats just going to go from one callback to another... Every way i think of doing it seems blocked by something...
So does anyone who knows what im going on about have any advice or ways they have made this process run all from actionscript?
I know this kinda goes against the point of it being asynchronous however i dont like mixing functionality and design, they *should* always be kept seperate, and the only easy way i can think of doing this is to make some looping movie clip which checks if the class has finished its communication, if it has then it triggers a function and trips a flag so everything else knows what to do, either way it seems illogical and a bit too much work for something simple...
Over to you guys!
Effective Method To Load Dynamic Content In To Flash?
I have to create some 30 to 40 pages of content in flash. The content has text, graphics, animations, interactivities like drag and drop, MCQ's etc. Data should come from outside flash say an xml file. Can any one suggest an effective way to do this. Thanks.
Asynchronous Code Execution
Hi,
the task is to go through textdata to search for a string inside it. Thats why this function blocks all other operation when I search inside a big text. Is there a way to call it asynchronous, so that it is not blocking operations?
Here the code, how the search starts:
code:
search_inputmask.onChanged = function()
{//starts timer, user dont have to press button, searching starts after 300ms
if(_global.waitingState == 0 || _global.waitingState == undefined)
{ _global.waitingState = setInterval(sendSearch,300); return; }
if(_global.waitingState != 0)
{ clearInterval(_global.waitingState); _global.waitingState = setInterval(sendSearch,300); }
}
function sendSearch()
{//sends searchstring to SearchEngine
clearInterval(_global.waitingState);
_global.waitingState = 0;
var resultSet = mySearchEngine.performSearch(search_inputmask.text ); //start the search
myResultarea.refresh(resultSet);
}
And here is a simplified version of a search loop. The blocking function is String.indexOf, because with bigger data this takes very long to go through.
code:
SearchEngine.prototype.performSearch = function(searchString)
{
...
for(var i=0; i<this.textData.length;i++)
{
var toCompare = this.textData[i];
var pos=0;
if((pos = toCompare.indexOf(searchString))!= -1)
{
this.resultSet.push(new Array(toCompare,i,pos)
}
}
...
}
return this.resultSet;
Philipp
Surely There Is A Better Way... (Asynchronous Rant)
Hey,
Ive been playing around with flash for a while now, and ive recently been bringing some stuff together from a project im working on, however ive just gotten to a section where i will have to daisychain about 8 functions together to do a fairly simple task... and im sat here thinking... surely there is a better way to do this... Here is the current scenario...
Ive got a main.swf file that deals with loading up other swf files internally, they all communicate via a static event handling class, and i made a custom event (SWFEvent) that deals with sending over small packets of information to let them communicate. They are not using any custom document classes, just the default ones that flash must generate within the swf file...
Now as you go through the various SWF files loaded the main.swf saves some of the data, such as unique ID and login times etc. Then finally once you have logged in and the main.swf has the required details set it loads up the final.swf file.
This file then has to do a small amount of tasks:
1) Load up an external config xml file
2) Use the data within the XML file to connect to the server
3) Once connected, Needs to send event to main.swf to get Unique ID stored within there
4) Once it retrieves the ID it sends it for validation to the server
5) Once validated it returns a shared object for the flash file to use
Now i thought this wouldnt be too hard, however i just thought of the simplest way to implement this, and it seems like a right mountain of functions.
1) I have to do a Loader request for the XML file, which then has 2 functions for onSuccess/onFailed. Providing the onSuccess function is called i can move onto task 2.
Current Functions: 2 (onSuccess/onFailed)
2) Then within the onSuccess function i will need to attempt a server connection with the XML details collected, this will then need an onSuccess/onFailed. Providing the onSuccess is called i can move onto task 3.
Current Functions: 4 addded (onSuccess/onFailed)
3) This needs to be split into 3 sub sections:
3-A) Within the previous onSuccess function i then need to send an event to the main.swf.
3-B) main.swf then needs to implement a listener for the swf communication event, when this function is called it then needs to respond to the final.swf file with the ID it has stored.
3-C) finally the final.swf needs to implement a listener for the returned event, once that is triggered it needs to move onto task 4.
Current Functions: 6 added (main.swf event, final.swf event)
4) This then sends the data to the server, which requires another onSuccess/onFailed function.
Current Functions: 8 added (onSuccess/onFailed)
5) Providing all the relevent onSuccess functions got to this point i then can start using the sharedobject, which im sure will need to implement other sync functions, but i guess at least this is a stopping point for the current scenario.
Current Functions: 8
Now as i work with other languages primarily actionscript is just a language im having to use on the side for projects, but it just seems so painful to do things. The above scenario that is used to just implement 1 sharedobject requires me to bloat my final.swf with 7 functions and add another to the main.swf. I dont really mind having all the functions but the thing that i dont like is the fact that they are all daisy chained. Each one calls the next, and so on, and eventually after linking a load of functions together i get 1 variable from a server.
Im hoping im just going about things the wrong way, but do any of you other actionscripters have to frequently do things like this? if so did you find any easier ways to do things than having to daisy chain masses of functions...
Maybe its just me, but regardless i thought i would make a post in the hope that someone can laugh at me and tell me im making a mountain out of a molehill and show me a simpler technique...
How To Create An Asynchronous Function
Hi all,
I'm writing an application that needs to do XML parsing, which takes a while and blocks the rest of my application. So I'd like to make my parsing function asynchronous. Any idea how async functions can be written ?
Regards,
Alex
Loadmovie Asynchronous Problem?
I have a number of movies and I am using loadmovie commands to move from movie to movie. I am getting unpredictable results and have used traces to try sorting out the problem. The action script seems to be executing out of order. I'm guessing that this is due to the asynchronous nature of action script. I'm hoping for some suggestions on how to deal with this problem. Thanks much for your help!
Synchronous And Asynchronous Xml Loading?
I have a nested xml.onLoad within a function (with a return statement in the function)
I need to wait for the xml.onLoad to be triggered before a return statement is sent.
Flash does not wait for the xml to finish loading it will just return "undefined"; If you list variables in the debugger you will see that the object exists. Because it has had ample time to load. Has any one come across this issue and if so have you come up with a solution
[FMX04] OnLoad Is Asynchronous?
Are all onLoad() calls asynchronous?
For example, if you have 2 calls to a LoadVars.sendAndLoad(), is there any way to guarantee the arrival or the order in which the onLoad() routine is called?
I have a flash script in which I need one onLoad to be called before the other one... is there a way to do this?? or to make one wait to execute until after the other arrives?
Thanks all...
Asynchronous Loading Through Classes...
Hello,
Im trying to load up some images in actionscript, but i thought i would wrap it up in a class, and make a custom event for when it fires so all other classes can be notified. However theory and practiase rarely work out, and like i expected the event just seems to get lost somewhere...
Now just to simplify it ive got 2 classes...
imageLoader (static) and baseImage
now baseImage will call setupImage(file) which will call imageLoader.loadFile(file), this will then do its stuff then set an internal event event.COMPLETE, then this SHOULD fire an event event.IMAGE_LOADED that will be picked up by baseImage.imageLoaded(eventData:event).
However it looks like the event gets lost inside the class somehow...
Anyone had anything like this happen before as i cant seem to diagnose the problem...
|