View Full Version : Execute Script
MadamZuZu
08-10-2007, 07:12 PM
hi :)
i need to execute a certain script on creatonComplete.
i dont want to open a new window.
the script is in Focus, which can be ruv via a html page.
if i do navegateToURL, a new page is opened. is there a way to tell flex to go and execute something without actually opening a window?
Thanks!
drkstr
08-10-2007, 10:10 PM
Try sendToUrl();
Regards,
...aaron
MadamZuZu
08-15-2007, 02:40 PM
i figure it out, i made a new hidden frame, and send my url to that request.
the problem i'm having is: my flex app, opens before the script has the time to execute.
is there a way to delay the "loading" of the Flex project by couple seconds?
or maybe there's a way to say - dont load, untill soandso html page has finished loading???
Thanks!
noflashlight
08-16-2007, 02:49 PM
Is this what you are after?
var srv:HTTPService = new HTTPService;
srv.addEventListener(ResultEvent.RESULT, runScript);
private function runScript():void{
//Code here gets executed on a HTTP Status 200
}
drkstr
08-16-2007, 08:43 PM
Either HTTPService or URLLoader will give you a return value. sendToURL() is only if you don't need a return.
Regards,
...aaron
MadamZuZu
08-22-2007, 03:17 PM
hey
var srv:HTTPService = new HTTPService;
srv.addEventListener(ResultEvent.RESULT, runScript);
private function runScript():void{
//Code here gets executed on a HTTP Status 200
}
this is great... :) thanks!
but is there a way to do this "pre-Flex-load", and show the "Loading" bar, while the status is not yet 200.... then then as it's 200, load the flex app..
or is there a "loading" bar component i can use, after the app has alrady loaded?
noflashlight
08-22-2007, 04:37 PM
var srv:HTTPService = new HTTPService();
srv.showBusyCursor = true;
That will show a clock for your mouse cursor when the request made, and will stop when completed.
Also I would look into the progressbar component... especially if you are making file upload requests to the server.
MadamZuZu
08-28-2007, 02:52 PM
i tried this example. and its not wokring :(
help pelase
private function runScript():void
{
//Code here gets executed on a HTTP Status 200
trace("in runScript");
}
private function Init():void
{
var srv:HTTPService = new HTTPService;
srv.url="http://www.myurl.html";
srv.addEventListener(ResultEvent.RESULT, runScript);
}
it never gets to runScript()
what am i doing wrong?
noflashlight
08-28-2007, 05:03 PM
Like any HTTP Request, you need to send it.
Also need to add the ResultEvent argument to runScript.
private function runScript(e:ResultEvent):void
{
//Shows the HTTP Response
trace(e.result.toString());
}
private function Init():void
{
var srv:HTTPService = new HTTPService;
srv.url="http://www.myurl.html";
srv.addEventListener(ResultEvent.RESULT, runScript);
srv.send();
}
MadamZuZu
10-01-2007, 06:57 PM
hi.
2 months later and i'm still on the same question.
let me rephrase my issue.
i want to open a page
while it's loading i want to show a busy cursor
when it's done. i want to run another Flex function and continue with my Flex stuff.
per our previous posts, i have this:
private function runScript(e:ResultEvent):void
{
//Shows the HTTP Response
trace(e.result.toString());
}
private function Init():void
{
var srv:HTTPService = new HTTPService();
srv.url="http://www.actionscript.org/forums/";
srv.addEventListener(ResultEvent.RESULT, runScript);
srv.send();
}
when i run it, i get this error:
[RPC Fault faultString="Error #1096: XML parser failure: Unterminated element." faultCode="Client.CouldNotDecode" faultDetail="null"]
at mx.rpc.http::HTTPService/http://www.adobe.com/2006/flex/mx/internal::processResult()
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()
at mx.rpc::Responder/result()
at mx.rpc::AsyncRequest/acknowledge()
at ::DirectHTTPMessageResponder/completeHandler()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()
why does it give me a XML error, if im not loading xml, but opening a regular page (with some javascript in it)
pleeaase help :(
noflashlight
10-01-2007, 07:43 PM
Umm.
Why are you requesting data from http://actionscript.org/forums?
You have to specify a resultFormat ( string, json, xml, Array )
XML is the default... hence why you have an error, because that URL request is gonna give you HTML.
If you are trying to just load a webpage... HTTPService is not what you want...
That class is used to make Asynchronous GET/POST requests to a server.
MadamZuZu
10-01-2007, 07:57 PM
actionscript.org is just an example.
yes im just trying to load an HTML.
what should i use?
is there another function that i can use to load HTML and listen for it's status? aka -> see when it's completly loaded?
noflashlight
10-01-2007, 08:09 PM
I think you're horribly confused.
What do you mean you want to "load" html? ...like in a browser window?
In that case you want something like sendToURL().
What exactly do you plan to do with this html after it is loaded? If the answer is "nothing"... then take out the line that says trace, and your error will be gone.
MadamZuZu
10-01-2007, 08:13 PM
the main idea is:
i'm trying to create an XML from a database. to do that with some javascript in my HTML.
the XML is used to populate a combo box in Flex.
i think i am confused.
i can't figure out how to dynamically create my XML. and have the combo box "wait" untill it's created to populate.
does this make sence?
noflashlight
10-01-2007, 08:30 PM
the main idea is:
i'm trying to create an XML from a database. to do that with some javascript in my HTML.
the XML is used to populate a combo box in Flex.
Maybe you should learn a little bit more about XML first...
Javascript is client side. If you want to create dynamic XML you need to use a server-side language like PHP. Or if it's static you can just write the XML document by hand
<xml>
<data>foo</data>
</xml>
Place that on a webserver, and request it like http://webserver.com/foo.xml
The XML file you are requesting can only have XML in it (not javascript). If you use PHP the processing is done on the server and the only thing returned to the client is the XML.
MadamZuZu
10-01-2007, 08:38 PM
im using webFOCUS to create the xml.
html calls a webFocus client, which then creates it and puts it on the server.
i want to then be able to use Flex to access it.
back to my question. is there something else i can use to call a HTML page and return/listen to it's STATUS?
noflashlight
10-01-2007, 08:48 PM
I'm not sure what web focus does,
but either way... here is what you need regardless.
You need a URL like http://something.com/xmlfeed that returns you ONLY xml... and nothing else. If anything but XML is returned, Flex will choke when it tries to parse it.
If you want to see what is being returned to Flex... simply go to that same url in a browser window and right click -> view source... Flex sees what you see. If you see anything like javascript or HTML or anything that does not form a valid XML document, Flex will take a ride on the FAIL BOAT!
If you need further help, post the URL you are requesting.
Whatever it is, if you get XML parsing errors, then it's not valid XML.
MadamZuZu
10-01-2007, 08:58 PM
alright, thank.
maybe my problem is not in flex but with the creation of the xml then.
i thought i could resolve it via flex somehow, but i guess not.
from what i understand, the XML has to be already made when i go to get it, i can't create one right there and then.
noflashlight
10-01-2007, 09:02 PM
i can't create one right there and then.
Correct.
But you can use a server-side language to generate it before it is returned to flex.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.