[AS3]as3中与加载的对象交互的例子源代码
[AS3]as3中与加载的对象交互的例子源代码
[AS3]as3中与加载的对象交互的例子源代码
- 代码
- flashone.as
- package {
- import flash.display.Loader;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.events.StatusEvent;
- import flash.net.LocalConnection;
- import flash.net.URLRequest;
- import flash.text.TextField;
- import flash.text.TextFieldAutoSize;
- import flash.text.TextFieldType;
- import flash.display.DisplayObject;
- public class FlashOne extends Sprite {
- private var conn:LocalConnection;
- private var loadFlashTow:Loader;
- // UI elements
- private var messageLabel:TextField;
- private var message:TextField;
- private var sendBtn:Sprite;
- public function FlashOne() {
- this.loadFlashTow=new Loader();
- this.loadFlashTow.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
- this.loadFlashTow.y=100;
- this.loadFlashTow.x=100;
- this.loadFlashTow.load(new URLRequest("FlashTow.swf"));
- buildUI();
- sendBtn.addEventListener(MouseEvent.CLICK, sendMessage);
- conn = new LocalConnection();
- conn.addEventListener(StatusEvent.STATUS, onStatus);
- }
- private function sendMessage(event:MouseEvent):void {
- conn.send("myConnection", "lcHandler", message.text);
- }
- private function onStatus(event:StatusEvent):void {
- switch (event.level) {
- case "status":
- trace("LocalConnection.send() succeeded");
- break;
- case "error":
- trace("LocalConnection.send() failed");
- break;
- }
- }
- private function completeHandler(event:Event){
- var _content:DisplayObject = event.target.content;
- this.addChild(loadFlashTow);
- }
- private function buildUI():void {
- const hPadding:uint = 5;
- // messageLabel
- messageLabel = new TextField();
- messageLabel.x = 10;
- messageLabel.y = 10;
- messageLabel.text = "Text to send:";
- messageLabel.autoSize = TextFieldAutoSize.LEFT;
- addChild(messageLabel);
- // message
- message = new TextField();
- message.x = messageLabel.x + messageLabel.width + hPadding;
- message.y = 10;
- message.width = 120;
- message.height = 20;
- message.background = true;
- message.border = true;
- message.type = TextFieldType.INPUT;
- addChild(message);
- // sendBtn
- sendBtn = new Sprite();
- sendBtn.x = message.x + message.width + hPadding;
- sendBtn.y = 10;
- var sendLbl:TextField = new TextField();
- sendLbl.x = 1 + hPadding;
- sendLbl.y = 1;
- sendLbl.selectable = false;
- sendLbl.autoSize = TextFieldAutoSize.LEFT;
- sendLbl.text = "Send";
- sendBtn.addChild(sendLbl);
- sendBtn.graphics.lineStyle(1);
- sendBtn.graphics.beginFill(0xcccccc);
- sendBtn.graphics.drawRoundRect(0, 0, (sendLbl.width + 2 + hPadding + hPadding), (sendLbl.height + 2), 5, 5);
- sendBtn.graphics.endFill();
- addChild(sendBtn);
- }
- }
- }
http://www.cnblogs.com/crkay/archive/2010/05/31/1747856.html
- 代码
- flashtow.as
- package {
- import flash.display.Sprite;
- import flash.net.LocalConnection;
- import flash.text.TextField;
- public class FlashTow extends Sprite {
- private var conn:LocalConnection;
- private var output:TextField;
- public function FlashTow() {
- buildUI();
- conn = new LocalConnection();
- conn.client = this;
- try {
- conn.connect("myConnection");
- } catch (error:ArgumentError) {
- trace("Can't connect...the connection name is already being used by another SWF");
- }
- }
- public function lcHandler(msg:String):void {
- output.appendText(msg + "\n");
- }
- private function buildUI():void {
- output = new TextField();
- output.background = true;
- output.border = true;
- output.wordWrap = true;
- addChild(output);
- }
- }
- }
热门文章推荐
- [Red5]Red5之Flash流媒体服务器的安装与使用教程完整版(组图)
- [rtsp]设置海康配置DDNS远程访问的用户手册(组图说明)
- [live555]live555直播rtsp流
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [FFmpeg]FFmpeg实现监控摄像头的RTSP协议转RTMP协议直播
- [海康]海康网络摄像机激活功能图文教程
- [RED5]搭建RED5直播用流媒体服务(搭直播环境)
请稍候...