编写自己的 flex Application

实现

flex 开发中,写一个自己的 Application,如下

package org.pyamf.examples.socket
{
	/**
	 * Copyright (c) 2007-2009 The PyAMF Project.
	 * See LICENSE.txt for details.
	 */
	
	import flash.events.Event;
	
	import mx.controls.Button;
	import mx.core.Application;
	import mx.events.FlexEvent;
	import flash.system.Security;
	
	/**
	 * This examples shows how to use Socket class in ActionScript 3,
	 * that allows you to make socket connections and to read and write
	 * raw binary data.
	 * 
	 * @author Thijs Triemstra ([email protected])
	 */
	public class SocketExample extends Application
	{
		public var start_btn: Button;
		public var stop_btn	: Button;
		
		private var _server	: PythonSocket;
..................

在 mxml 中这样来用:

<?xml version="1.0" encoding="utf-8"?>
<pyamf:SocketExample xmlns:mx="http://www.adobe.com/2006/mxml"
					 xmlns:pyamf="org.pyamf.examples.socket.*"
					 backgroundColor="white" alpha="1"
					 >
	
	
	<mx:Panel title="PyAMF - Binary Socket Example">
		<mx:TextArea id="status_txt" width="350" height="300" htmlText="{ log }" textIndent="3" editable="false"
					 valueCommit="{status_txt.verticalScrollPosition = status_txt.maxVerticalScrollPosition}"/>
		
		<mx:ControlBar horizontalAlign="center">
			<mx:Button id="start_btn" label="Start" click="startFeed()" enabled="false"/>
			<mx:Button id="stop_btn" label="Stop" click="stopFeed()" enabled="false"/>
		</mx:ControlBar>
	</mx:Panel>
	<mx:Panel title="version 4"/>
	
</pyamf:SocketExample>

好处是什么?

好处就是不用在 mxml 中,嵌入 actionScript.

把要调的函数实现在这个 class 中.

mxml 只管布局就可以了.