﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-yellowstonemay-文章分类-flex 3 -- blazeds</title><link>http://www.blogjava.net/yellowstonemay/category/40572.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 02 Jul 2009 20:36:48 GMT</lastBuildDate><pubDate>Thu, 02 Jul 2009 20:36:48 GMT</pubDate><ttl>60</ttl><item><title>use localConnection to comunicate between SWF</title><link>http://www.blogjava.net/yellowstonemay/articles/285246.html</link><dc:creator>yellowstone</dc:creator><author>yellowstone</author><pubDate>Thu, 02 Jul 2009 13:27:00 GMT</pubDate><guid>http://www.blogjava.net/yellowstonemay/articles/285246.html</guid><wfw:comment>http://www.blogjava.net/yellowstonemay/comments/285246.html</wfw:comment><comments>http://www.blogjava.net/yellowstonemay/articles/285246.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yellowstonemay/comments/commentRss/285246.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yellowstonemay/services/trackbacks/285246.html</trackback:ping><description><![CDATA[Flex local connection is an amazing functionality. With it, you can have two SWF comunicate easily.<br />
<br />
Here is a simple example to demonstrate how it work base on Adobe training and my practice.<br />
<br />
On Sender(client) side:<br />
<font style="background-color: #c5e4c5">&nbsp;&lt;mx:Script&gt;<br />
&nbsp;&nbsp;&lt;![CDATA[<br />
&nbsp;&nbsp;&nbsp;import flash.net.LocalConnection;&nbsp;&nbsp; //do the import<br />
&nbsp;&nbsp;&nbsp;private var conn:LocalConnection;&nbsp;<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;private function init():void{<br />
&nbsp;&nbsp;&nbsp;&nbsp;conn = new LocalConnection();&nbsp; // create a new local connection instance<br />
&nbsp;&nbsp;&nbsp;&nbsp;conn.send("_mylocalconnection", "doCloseAgentPopup");&nbsp; //send request to receiver(server)&nbsp;side. "_mylocalconnection" is kind of connection node.&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// "doCloseAgentPopup" is the function to call. you can also use&nbsp;some parameters followed it<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;]]&gt;<br />
&nbsp;&lt;/mx:Script&gt;<br />
</font><br />
On Receiver(server) side:<br />
<font style="background-color: #c5e4c5">&nbsp;&nbsp;&nbsp;&nbsp;import flash.net.LocalConnection;<br />
&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp; var conn:LocalConnection;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp;private function initLocalConn():void<br />
&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;conn = new LocalConnection();<br />
&nbsp;&nbsp;&nbsp;&nbsp;conn.client = this;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;notice that this is called&nbsp;"client" here. I think it mean it is&nbsp;a client to provide service to other side.<br />
&nbsp;&nbsp;&nbsp;&nbsp;conn.connect("_mylocalconnection");&nbsp;&nbsp;&nbsp;&nbsp;// connect to the node "_mylocalconnection"&nbsp;and wait call from other side<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;public function doCloseAgentPopup():void{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//this is&nbsp;the function to call from sender side. in this function, do general flex funtion as you like<br />
&nbsp;&nbsp;&nbsp;&nbsp;if(MyTitleWindow != null){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PopUpManager.removePopUp(agentTitleWin);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;agentTitleWin = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;checkAgentStatus();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;}<br />
</font><br />
That is it. simple but work well. Enjoy it!<br />
<br />
<img src ="http://www.blogjava.net/yellowstonemay/aggbug/285246.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yellowstonemay/" target="_blank">yellowstone</a> 2009-07-02 21:27 <a href="http://www.blogjava.net/yellowstonemay/articles/285246.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>working with session on BlazeDS</title><link>http://www.blogjava.net/yellowstonemay/articles/284980.html</link><dc:creator>yellowstone</dc:creator><author>yellowstone</author><pubDate>Wed, 01 Jul 2009 08:59:00 GMT</pubDate><guid>http://www.blogjava.net/yellowstonemay/articles/284980.html</guid><wfw:comment>http://www.blogjava.net/yellowstonemay/comments/284980.html</wfw:comment><comments>http://www.blogjava.net/yellowstonemay/articles/284980.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yellowstonemay/comments/commentRss/284980.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yellowstonemay/services/trackbacks/284980.html</trackback:ping><description><![CDATA[when applying BlazeDS, you might notice that in web.xml, a listener named "<font style="background-color: #c5e4c5">flex.messaging.HttpFlexSession</font>" should be inserted.<br />
It is how BlazeDS can work with session data. <br />
BlazeDS provide several classes which is useful for get access to the session and the HTTP pieces of the session, such as the HTTP servlet request and response. This lets you access HTTP data when you use a Flex application in the context of a larger web application where other classes, such as JSPs or Struts actions, might have stored information.<br />
<li>flex.messaging.FlexContext
<li>flex.messaging.FlexSession </li>
<p>&nbsp;</p>
<p>The following example shows a Java class that calls <code>FlexContext.getHttpRequest()</code> to get an HTTPServletRequest object and calls <code>FlexContext.getFlexSession()</code> to get a FlexSession object. By exposing this class as a remote object, you can make it accessible to a Flex client application; you place the compiled class in the WEB_INF/classes directory </p>
<div class="listing">
<pre>package myROPackage;
import flex.messaging.*;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SessionRO {
public HttpServletRequest request;
public FlexSession session;
public UsefulRemoteObject() {
request = FlexContext.getHttpRequest();
session = FlexContext.getFlexSession();
}
public String getSessionId() throws Exception {
String s = new String();
s = (String) session.getId();
return s;
}
public String getHeader(String h) throws Exception {
String s = new String();
s = (String) request.getHeader(h);
return h + "=" + s;
}
}
</pre>
</div>
<p>The following example shows a Remoting Service destination definition that exposes the SessionRO class as a remote object. You add this destination definition to your Remoting Service configuration file.</p>
<div class="listing">
<pre>...
&lt;destination id="myRODestination"&gt;
&lt;properties&gt;
&lt;source&gt;myROPackage.SessionRO&lt;/source&gt;
&lt;/properties&gt;
&lt;/destination&gt;
...
</pre>
</div>
<p>The following examples shows an ActionScript snippet for calling the remote object from a Flex client application. You place this code inside a method declaration.</p>
<div class="listing">
<pre>...
ro = new RemoteObject();
ro.destination = "myRODestination";
ro.getSessionId.addEventListener("result", getSessionIdResultHandler);
ro.getSessionId();
...
</pre>
</div>
<script language="JavaScript1.2" type="text/javascript">
   <!-- document.write(WWHRelatedTopicsDivTag() + WWHPopupDivTag());
   // -->
  </script>
<img src ="http://www.blogjava.net/yellowstonemay/aggbug/284980.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yellowstonemay/" target="_blank">yellowstone</a> 2009-07-01 16:59 <a href="http://www.blogjava.net/yellowstonemay/articles/284980.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>