Flex组件不能显示问题:
1.组合组件要定义宽和高
package component
{
import mx.controls.Label;
import mx.core.UIComponent;
public class LabelComponent extends UIComponent
{
public function LabelComponent()
{
super();
}
override protected function createChildren():void{
super.createChildren();
var label:Label = new Label();
label.text = "success";
this.addChild(label);
}
}
}
2.html 中调用swf 以及传递参数
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="FetchInfo" width="800" height="268"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="/script/FetchInfo.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src="/script/FetchInfo.swf?sourceid=<s:property value="diserver.id"/>"allowFullScreen="true" quality="high" bgcolor="#869ca7"
width="800" height="268" name="FetchInfo" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
swf中得到参数的值:
sourceid=Application.application.parameters["sourceid"];
3.swf 发送给服务端,接收返回的参数
使用HttpService对象
<mx:HTTPService id="loginService" resultFormat="text" result="
{
doResultHandle(event);
return;
}
" />
loginService.url ="/crawl/returnCrawlInfo2.dhtml";
loginService.addEventListener(mx.rpc.events.FaultEvent.FAULT, getConfiguration);
var loc1:*=new flash.net.URLVariables();
loc1.dt = int(Math.random() * 10);
loc1.sourceid=int(sourceid);
loginService.send(loc1);
Action 通过:
request.getParameter("sourceid")得到swf 传递的值
返回的处理:
private function doResultHandle(arg1:mx.rpc.events.ResultEvent):void
{
var loc1:*=arg1.result.toString();
var loc2:*=com.adobe.serialization.json.JSON.decode(loc1);
if (loc2)
{
url1 = loc2.url;
port = loc2.port;
}
start();
return;
}
其中Action 如果要输出直接JSon对象:使用过滤器
4.如何将socket 取得的数 放在DataGrid 中
1. 定义arrayClllection
2.绑定数据
3.添加数据
<mx:ArrayCollection id="arrColl">
<mx:source>
<mx:Array>
</mx:Array>
</mx:source>
</mx:ArrayCollection>
使用{}绑定
<mx:DataGrid id="fetcherInfo" dataProvider="{arrColl}" height="245" width="785" x="10" y="10">
<mx:columns>
<mx:DataGridColumn headerText="地址" itemRenderer="cis_inlineComponent1" dataField="url" sortable="false" width="480" draggable="false" textAlign="center" headerStyleName="box1" color="#000000">
</mx:DataGridColumn>
<mx:DataGridColumn headerText="站点" width="220" draggable="false" sortable="false" dataField="site" headerStyleName="box1" textAlign="center" />
<mx:DataGridColumn headerText="状态" itemRenderer="cis_inlineComponent2" sortable="false" width="100" draggable="false" dataField="status" headerStyleName="box1" textAlign="center">
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
建立事件响应
private function socketConn():void
{
socket.connect(url1, port);
trace(url1+":"+port);
//we.text="socketConn:"+url1+":"+port;
socket.addEventListener(flash.events.Event.CONNECT, onConnnect);
socket.addEventListener(flash.events.Event.CLOSE, onClose);
socket.addEventListener(flash.events.ProgressEvent.SOCKET_DATA, runFun);
return;
}
读取数据
while (socket.bytesAvailable)
{
//we.text="runFun"+(number++);
msg = socket.readMultiByte(socket.bytesAvailable, "utf-8");
var temp:*=com.adobe.serialization.json.JSON.decode(msg);
if(temp){
status=temp.status;
if(status == "ok"){
temp.status="正常";
}else{
temp.status="失败";
}
arrColl.addItem(temp);
//we.text="runFun"+(msg);
}
}
return;