My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Links

Updated (2009-11-12)

coming soon!!! (@2009-11-13)

Global:

AS do AS things (code), JS do JS things (code), only communicate with me (bridge)!

AS and JS are doing their own things, only use bridge in communication.

Actionscript and Javascript communication frame class

by KingFo http://www.xintend.com

Version

  • 1.0.2.4(alpha 2)
    1. add swf setup wizard
    2. bugfix
    3. supply multiplayer event
  • 1.0.2.3(alpha 1)
    1. alpha 1 release
    2. bugfix
  • 0.0.2.2
    1. remove swf function
    2. normal test
  • 0.0.2.1
    1. add create swf function
    2. normal test
  • 0.0.1.0
    1. core test

About AJBridge

Features:

  1. unified Event
Future plans:
  1. finish debuger
  2. add Flash Player controller.

Examples

Ver. 1.0.2.4(alpha 2)

AS3 code

  package {
	import com.xintend.external.ajb.AJBridge;
	import com.xintend.external.ajb.event.AJBridgeEvent;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.external.ExternalInterface;
	import flash.system.Security;
	import flash.system.System;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	/**
	 * ...
	 * @author  Kingfo[Telds longzang]  
	 * @email	oicuicu@gmail.com
	 * @site	http://www.xintend.com
	 * @ver     1.0.0.1
	 */
	public class Test extends Sprite {
		
		public function Test():void {
			Security.allowDomain('*');	
			
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
			
			
		}
		
		private function renderHandler(e:Event):void {
			
		}
		
		private function init(e:Event = null):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			
			stage.align = "TL";
			stage.scaleMode = "noScale";
			
			tfmt = new TextFormat(null, 12, 0xFFFFFF);
			
			tf.background = true;
			tf.backgroundColor = 0x0;
			tf.width = stage.stageWidth;
			tf.height = stage.stageHeight;
			tf.defaultTextFormat = tfmt;
			addChild(tf);
			
			foo()
		}
		
		
		
		public function foo():void {
			ajb.register(this);
			ajb.dispathcer.addEventListener(AJBridgeEvent.AJBRIDGE_READY, ajbHanlder);
			ajb.receiver.addEventListener(AJBridgeEvent.AJBRIDGE_READY, ajbHanlder);
		}
		
		private function ajbHanlder(event:AJBridgeEvent):void {
			switch(event.type) {
				case AJBridgeEvent.AJBRIDGE_READY:
					output('objectID:' + AJBridge.objectID);
					output('callJS:' + ajb.dispathcer.callJS('alert', 'FromAJ:callJS' ));
					output('dispatchJSEvent:' + ajb.dispathcer.dispatchJSEvent(new AJBridgeEvent({type:"CallJS",details:'FromAS:dispatchJSEvent'})));
				break;
			}
		}
		
		
		
		
		
		private function output(o:*):void {
			var str:String = String(o); 
			tf.appendText(str);
			tf.appendText('\n');
		}
		
		private var tf:TextField = new TextField();
		private var tfmt:TextFormat 
		
		private var ajb:AJBridge = AJBridge.getInstance();
		
	}
	
}

example-3 (Dynamic):

  1. JS:
  2. var swfID = "myID";
    AJBridge.swf.wizard.addSWF('../../bin/AJBridge.swf','swfCtt',swfID,'9.0.0');
    
    
    var RichEvent = AJBridge.event.RichEvent;
    
    function foo1(){
    	alert("onDomReady foo1")
    }
    function foo2(){
    	alert("onDomReady foo2")	
    }		
    function foo3(){
    	alert("onSWFReady foo3")
    }
    function foo4(){
    	alert("onSWFReady foo4")
    }
    function callJSI(event){
    	alert('callJSI:' + event.details);
    	AJBridge.util.later(5000,this,AJBridge.swf.wizard.removeSWF,swfID);
    }
    
    AJBridge.dom.onDomReady([foo1,foo2]);	
    AJBridge.swf.onSWFReady(swfID,[foo3,foo4]);
    AJBridge.swf.addEventListener(new RichEvent({id:swfID,type:'CallJS'}),callJSI);
  3. HTML Fragment:
  4. 		<script src="AJBridge.source.js" type="text/javascript"></script>
    		
    		<div id="swfCtt"></div>

example-2 (Static):

  1. JS:
  2. var swfID = "myFlashContent";
    
    var RichEvent = AJBridge.event.RichEvent;
    
    function foo1(){
    	alert("onDomReady foo1")
    }
    function foo2(){
    	alert("onDomReady foo2")	
    }		
    function foo3(){
    	alert("onSWFReady foo3")
    }
    function foo4(){
    	alert("onSWFReady foo4")
    }
    function callJSI(event){
    	alert('callJSI:' + event.details);
    }
    
    AJBridge.dom.onDomReady([foo1,foo2]);	
    AJBridge.swf.onSWFReady(swfID,[foo3,foo4]);
    AJBridge.swf.addEventListener(new RichEvent({id:swfID,type:'CallJS'}),callJSI);
  3. HTML Fragment:
  4. 		<script src="AJBridge.js" type="text/javascript"></script>
    		
    		
    		<div>
    			<object  type="application/x-shockwave-flash" data="../bin/AJBridge.swf"  width="800" height="600" name="myFlashContent" id="myFlashContent"  >
    				<param name="movie" value="../bin/AJBridge.swf" />
    				<param name="allowfullscreen" value="true" />
    				<param name="allowscriptaccess" value="always" />
    				<param name="allownetworking" value="all" />				
    			</object>
    		</div>

Ver 1.0.2.3(alpha 1)

example-1:

var swfID = "myFlashContent";
function foo1(){
	alert("onDomReady foo1")
}
function foo2(){
	alert("onDomReady foo2")	
}		
function foo3(){
	alert("onSWFReady foo3")
}
function foo4(){
	alert("onSWFReady foo4")
}
function callJSI(data){
	alert(data)
}

AJBridge.dom.onDomReady([foo1,foo2]);	
AJBridge.swf.onSWFReady([foo3,foo4]);
AJBridge.swf.addEventListener(swfID,'callJS',callJSI);

Powered by Google Project Hosting