Hello dear guys,
i want know about ExternalInterface - just i have same problem with String or Array - if i like this.
But i am working with AS3 with in-block Javascript like trick by Facebook Api Libraries.
I know same functions for Boolean and Object right..
Code is MyLibrary.as
package ....
{
import flash.external.ExternalInterface;
public class MyLibraray
{
/**
* MyLibrary Exit
*/
private static var _exit:Object;
public static function Exit():void
{
try{
if(ExternalInterface.available){
_exit = ExternalInterface.call(jsBirdge.script());
_exit = ExternalInterface.call("JSL.jsExit"); //
}
}catch( error:Error) {}
}
} }
And jsBirdge.as <- It is in-block with Javascript into XML Format and Doement Format like Javascript Version into Actionscript
package ...
{
import flash.external.ExternalInterface;
public class jsBirdge
{
private static var NS:String = "JSL";
public static function script():String
{
try{
if(ExternalInterface.available){
ExternalInterface.call(script_js);
ExternalInterface.call("JSL.setSWFObject", ExternalInterface.objectID);
}
}catch( error:Error) {}
return NS;
}
private static const script_js:XML =
<script>
<![CDATA[
function (){
var curwin = Titanium.UI.currentWindow;
JSL= {
setSWFObjectID: function( swfObjectID ) {
JSL.swfObjectID = swfObjectID;
},
/* Same Functions */
jsExit : function(){
Titanium.exit();
}
};
}
]]>
</script>;
}
}
How does ExternalInterace work with currect type?
If i use custom call like exit for Titanium Desktop than ExternalInterface will check currect type - like function type exit() = Titanium.exit(); as Type "String"
Or another example: File, FileSystem and FileStream are types as object, is it right?
Or Booleam Example true or false as type Booleam. ...
Is it posskible that externalInterface works fine with any types/functions?
I have been tested with ExternalInterface and In-Block Javascript = IT works fine... Look out! http://developer.appcelerator.com/question/135288/how-do-you-know-flas h-and-titanium
But i hate disturbated communication function like GWT external / fscommand...
I want use only AS3 / JS. Just i miss this nice example because i don't forget - where are nice examples? I wish because you would say me about currect result ![]()
Thanks i hope because i get nice answer / result for currect types / function for externalinterface via inblock: Javascript.
Hi,
I am not really clear with your above post. But you can communicate with javascript from flex by the below way.
Javascript:
function CallMe()
{
alert("Call Me");
}
function CallMeWithArg(value)
{
alert("This is your value: " + value);
}
Action Script:
ExternaInterface.call('CallMe'); //without argument.
ExternaInterface.call('CallMeWithArg', 'HelloWorld'); //with argument.
Hey @Sathyamoorthi,
thank you i understand.
If i am using only ExternalInterface like Javascript with in-block into AS3 than as3 library ( swc ) works complety. Example: I am using with Titanium Desktop.
I will call externalInterface by Javascript's Library.
Look example:
Application.as:
/**
* SourceSkyBoxer's Library
*
* Support for Titanium Desktop
*/
package net.sourceskyboxer.as3titan
{
import flash.external.ExternalInterface;
public class Application
{
/**
* Application Exit
*/
public static var _exit:String;
public static function Exit():String
{
try{
if(ExternalInterface.available){
_exit = ExternalInterface.call(jsBirdgeTitanium.script());
_exit = ExternalInterface.call("TIAS.jsExit");
}
}catch( error:Error) {}
return _exit;
}
/**
* Application Restart
*/
public static var _restart:String;
public static function Restart():String
{
try{
if(ExternalInterface.available){
_restart = ExternalInterface.call(jsBirdgeTitanium.script());
_restart = ExternalInterface.call("TIAS.jsRestart");
}
}catch( error:Error) {}
return _restart;
}
/**
* Application Maximize
*/
public static var _maximize:String;
public static function Maximize():String
{
try{
if(ExternalInterface.available){
_maximize = ExternalInterface.call(jsBirdgeTitanium.script());
_maximize = ExternalInterface.call("TIAS.jsMaximize");
}
}catch( error:Error) {}
return _maximize;
}
/**
* Application Restore / Unmaximize
*/
public static var _restore:String;
public static function Restore():String
{
try{
if(ExternalInterface.available){
_restore = ExternalInterface.call(jsBirdgeTitanium.script());
_restore = ExternalInterface.call("TIAS.jsRestore");
}
}catch( error:Error) {}
return _restore;
}
/**
* Application Minimize
*/
public static var _minimize:String;
public static function Minimize():String
{
try{
if(ExternalInterface.available){
_minimize = ExternalInterface.call(jsBirdgeTitanium.script());
_minimize = ExternalInterface.call("TIAS.jsMinimize");
}
}catch( error:Error) {}
return _minimize;
}
/**
* Application Super this...
*/
public function Application():void
{
super();
}
}
}
And jsBirdgeTitanium.as:
/**
* SourceSkyBoxer's Library
*
* Support for Titanium Desktop
*/
package net.sourceskyboxer.as3titan
{
import flash.external.ExternalInterface;
public class jsBirdgeTitanium
{
public static var NS:String = "TIAS";
public static function script():String
{
try{
if(ExternalInterface.available){
ExternalInterface.call(script_js);
ExternalInterface.call("TIAS.setSWFObject", ExternalInterface.objectID);
}
}catch( error:Error) {}
return NS;
}
public static const script_js:XML =
<script>
<![CDATA[
function (){
var curwin = Titanium.UI.currentWindow;
TIAS = {
setSWFObjectID: function( swfObjectID ) {
TIAS.swfObjectID = swfObjectID;
},
/* Application Functions */
jsExit : function(){
Titanium.App.exit();
},
jsRestart : function(){
Titanium.App.restart();
},
jsMaximize : function(){
curwin.maximize();
},
jsRestore : function(){
curwin.unmaximize();
},
jsMinimize : function(){
curwin.minimize();
},
/* System Functions */
jsGetplfo : function(){
Titanium.getPlatform(os);
}
};
}
]]>
</script>;
}
}
How do i know? When do i click same without "()" than ExternalInterface can't work because it has same problem with special structures of Javascript. If i check error for Javascript Structure simple with Adobe Dreamweaver CS5 than i add completed Javascript In-Block into AS3 ( jsBirdgeTitanium.as )
I knew nice trick by FaceBook's Library - Did you know about FaceBook's Library for swc files and Sources. I have been foound Javascript In-Block by FaceBook:
FaceBook_graphi / api / com / facebook / core / FacebookJSBridge.as
/*
Copyright (c) 2010, Adobe Systems Incorporated
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Adobe Systems Incorporated nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.facebook.graph.core {
import flash.external.ExternalInterface;
/**
* Class that wraps javascript code for communicating with Facebook Javascript SDK.
* This class replaced the previous FBJSBridge.js file.
*
*/
public class FacebookJSBridge {
public static const NS:String = "FBAS";
public function FacebookJSBridge() {
try {
if( ExternalInterface.available ) {
ExternalInterface.call( script_js );
/*Get a reference to the embedded SWF (object/embed tag). Note that Chrome/Mozilla Browsers get the 'name' attribute whereas IE uses the 'id' attribute.
This is important to note, since it relies on how you embed the SWF. In the examples, we embed using swfObject and we have to set the attribute 'name' the
same as the id.*/
ExternalInterface.call( "FBAS.setSWFObjectID", ExternalInterface.objectID );
}
} catch( error:Error ) {}
}
private const script_js:XML =
<script>
<![CDATA[
function() {
FBAS = {
setSWFObjectID: function( swfObjectID ) {
FBAS.swfObjectID = swfObjectID;
},
init: function( opts ) {
var options = FB.JSON.parse( opts );
FB.init( options );
FB.Event.subscribe( 'auth.authResponseChange', function( response ) {
FBAS.updateSwfAuthResponse( response.authResponse );
} );
},
setCanvasAutoResize: function( autoSize, interval ) {
FB.Canvas.setAutoResize( autoSize, interval );
},
setCanvasSize: function( width, height ) {
FB.Canvas.setSize( { width: width, height: height } );
},
login: function( opts ) {
FB.login( FBAS.handleUserLogin, FB.JSON.parse( opts ) );
},
addEventListener: function( event ) {
FB.Event.subscribe( event, function( response ) {
FBAS.getSwf().handleJsEvent( event, FB.JSON.stringify( response ) );
} );
},
handleUserLogin: function( response ) {
FBAS.updateSwfAuthResponse( response.authResponse );
},
logout: function() {
FB.logout( FBAS.handleUserLogout );
},
handleUserLogout: function( response ) {
swf = FBAS.getSwf();
swf.logout();
},
ui: function( params ) {
obj = FB.JSON.parse( params );
method = obj.method;
cb = function( response ) { FBAS.getSwf().uiResponse( FB.JSON.stringify( response ), method ); }
FB.ui( obj, cb );
},
getAuthResponse: function() {
authResponse = FB.getAuthResponse();
return FB.JSON.stringify( authResponse );
},
getLoginStatus: function() {
FB.getLoginStatus( function( response ) {
if( response.authResponse ) {
FBAS.updateSwfAuthResponse( response.authResponse );
} else {
FBAS.updateSwfAuthResponse( null );
}
} );
},
getSwf: function getSwf() {
return document.getElementById( FBAS.swfObjectID );
},
updateSwfAuthResponse: function( response ) {
swf = FBAS.getSwf();
if( response == null ) {
swf.authResponseChange( null );
} else {
swf.authResponseChange( FB.JSON.stringify( response ) );
}
}
};
}
]]>
</script>;
}
}
That is "In-Block" for Javascript into AS3.
I would like this because ExternalInterface is very better than get4flex or get4air.
Did you know about ExternalInterface - communicate is very better or went bad?
I would find for currect structure for Actionscript 3 and Javascript communication for externalinterface with different types like variable, array, boolean and ayn functions / types?
What does externalinterface support with types by Javascript?
I know void type - it is very simple only click. But i need any types. Thanks!
North America
Europe, Middle East and Africa
Asia Pacific