Mailing List
Home
Forum Home
Flash Pro
Subjects
Firework Effect
setInterval bug identified and fixed
setInterval bug identified and fixed
ScrollPane component doesn 't auto update
Help: MX 2004 How to script a print button to print the entire sli
Event Dispatcher between classes
memory management removeMovieClip /
MX2004 Dataset itemClassName
Order of events per frame
XML to Object help
Textfield prototype question
Flash and QuickTime VR
Reading and displaying RSS feeds in Flash MX
Flash MX 2004 Sucks
AW: [Flashcoders] Switch/Case vs If/else
AW: [Flashcoders] Switch/Case vs If/else
Flash Interface with 10mb xml file
Web Service Results
Listener Object 's best practice
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
LoadVars returning XML doc & EventDispatcher

LoadVars returning XML doc & EventDispatcher

2004-02-25       - By Pat Ryan

 Back

Hi Everyone,

I have a couple of questions.

I have an existing Struts web application, that I am retrofitting a Flash
interface to.  I have the need to post form data to Struts like URLs.  The
returned data is an XML document, so its a hybrid between what LoadVars does and
what XML object does.

Is there an 'out of the box' way to post data to the servlet and receive an XML
doc back?

Going under the assumption there is not, I have written something that works -
except for the very final step of notifying the caller that the XML document is
ready.

The problem appears to be with the way I have EventDispatcher setup.  My
listener is never getting called.  Here is the code for the class that handles
the posting of form data, and the creation of an XML document from the servlet:

============================ POST4XML.as =============
import mx.events.EventDispatcher;

class Post4XML  {

private var _receiveLoadVars:LoadVars;
private var _sendLoadVars:LoadVars;
private var _url:String;
private var _xml:XML;

public var addEventListener:Function;
public var removeEventListener:Function;
private var dispatchEvent:Function;


private function receiveOnData(data:String):Void {
     trace("receiveOnData: " + data );
     _xml = new XML();
     _xml.ignoreWhite = true;
     _xml.parseXML(data);
     trace("_xml.firstChild: " + _xml.firstChild );
     var eventObj:Object = {target:this, type:"xmlDocReady"};
     eventObj.xmlDoc = _xml ;
     dispatchEvent(eventObj);

}

public function Post4XML() {
     trace("Post4XML ctor...");
     mx.events.EventDispatcher.initialize(this);

     init();
}

public function addParam(name:String, value:String):Void {
     _sendLoadVars[name] = value;
}

public function setURL(url:String):Void {
     _url = url;
}

public function init():Void {
     _receiveLoadVars = new LoadVars();
     _sendLoadVars = new LoadVars();
     _url = "";
}

public function post():Void {
     _receiveLoadVars.onData = receiveOnData;
     _sendLoadVars.sendAndLoad(_url, _receiveLoadVars, "POST");
}


}

===========================================

Trace output:
Post4XML ctor...
Login button clicked:
receiveOnData: <?xml version="1.0" encodeing="iso-8859-1" ?>

<login results="true" />

_xml.firstChild: <login results="true" />

============================================

This is being setup in a Form class like:

class forms.LoginForm extends Form {

... detail deleted....

private function click():Void {
 trace("Login Button clicked: " );

 _post4XML.init();
 _post4XML.addParam("username", userNameText.text);
 _post4XML.addParam("password", passwordText.text);
 _post4XML.addParam("validate_login", "true");
 _post4XML.setURL("http://localhost:8080/myapp/ValidateLogin.do");
 _post4XML.addEventListener("xmlDocReady", this);
 _post4XML.post();

}

public function xmlDocReady(eventObj:Object):Void {
 trace("xmlDocReady: " + eventObj.xmlDoc );
}

}

I expected to see xmlDocReady in the trace output but I never do.  Can anyone
see a problem with this approach or can you suggest another approach to take to
solve this problem.

Thanks in advance.

Pat



=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Supported by Fig Leaf Software
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Be sure to check the archives and the wiki:
http://chattyfig.figleaf.com/
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:105245
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)




Earn $52 per hosting referral at Lunarpages.