ExternalInterface Called From LocalConnection
Hi. I have a flash application consisting of several windows all talking through a parent flash window over LocalConnection for calls to server and the browser etc.
The flash in the "child" windows calls the flash in the main parent window which in turn used an FSCommand to open/control other html windows.
We have recently upgraded the application to Flash8, and are taking advantage of the extra functionality of ExternalInterface calls (instead of FSCommand) to communicate with the page.
However, I now find that calls to any function in the parent flash with an ExternalInterface.call() that originates from a LocalConnection call from a child flash window is now failing. (was all working fine before with fscommand)
In fact more than failing - completely crashes the browser instance (ie6) and will no longer respond. No adverse CPU or memory use though...
Has anyone experienced this problem, and if so have you found a solution or workaround?
Thanks, Stu
ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 07-06-2006, 02:35 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
JavaScript Array Called Via ExternalInterface
The following is located in the HTML page
<script>
function getFlvList() {
var flv_array = new Array(0,1,2);
return flv_array;
}
</script>
With the following in Flash 8 ActionScript
var flv2_array:Array = Array(ExternalInterface.call("getFlvList"));
myLabel.text = flv2_array[0];
The label text becomes: 0,1,2 not: 0
It appears that rather than an array a String is being returned. This is not
true in Flex. Is this behavior to be expected?
Thanks.
[F8] Problem In Flash Player 9 Fullscreen, When Called From LocalConnection
Hi All,
I have a situation in which I have to make use of two flash movies in the webpage.
I am trying to communicate between these two movie through LocalConnection object, everything is working fine except the Flash Player 9 Fullscreen option.
In first movie there is a button called "Fullscreen" and in other movie I have a FlvPlayback component. So what I want to do is, when a user clicks the "Fullscreen" button then the flvplayback component in the other movie should use the flash player 9 fullscreen (occupying full monitor area).
Localconnection is working fine except the code Stage.displayState="fullScreen", Other commands in the function are working.
So any help from any of you will be very helpfull.
thanks in advance,
Vikas
Problem In Flash Player 9 Fullscreen, When Called From LocalConnection
Hi All,
I have a situation in which I have to make use of two flash movies in the webpage.
I am trying to communicate between these two movie through LocalConnection object, everything is working fine except the Flash Player 9 Fullscreen option.
In first movie there is a button called "Fullscreen" and in other movie I have a FlvPlayback component. So what I want to do is, when a user clicks the "Fullscreen" button then the flvplayback component in the other movie should use the flash player 9 fullscreen (occupying full monitor area).
Localconnection is working fine except the code Stage.displayState="fullScreen", Other commands in the function are working.
So any help from any of you will be very helpfull.
thanks in advance,
Vikas
[F8] ExternalInterface
I am doing the tutorial from adobes site font at http://www.adobe.com/devnet/flash/ar...ace_print.html
It teaches you how to call a JavaScript function and return a value via the external Interface.
I can call the JavaScript function and pass the parameters with ease. When it come to getting the return value, I always get undefined!!!!
here is my ActionScript
Code:
import flash.external.*;
var callJasFunction:String = "callJavaScript";
var msg:String = "OI!";
var returnValue:String = ExternalInterface.call(callJasFunction,msg).toString();
return_txt.text = returnValue;
Here is my HTML and JavaScript
Code:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>WTF!!!!!!!!!!</title>
<script language="JavaScript">
function callJavaScript(str){
alert(str);
return "ExternalInterface is now working";
}
</script>
</head>
<body bgcolor="#ffffff">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="768" height="100" id="001" align="middle">
<param name="allowScriptAccess" value="always" />
<param name="movie" value="001.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="001.swf" quality="high" bgcolor="#ffffff" width="768" height="100" name="001" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>
</html>
I also tried to set the allowScriptAccess to sameDomain, and uploading it to my server.
ExternalInterface And XML?
I am creating links in my flash movie using XML. Once I do I would like the links to send info to my HTML page using ExternalInterface. It works when I hard code the url like so:
ExternalInterface.call("ajaxpage", 'hardCode.htm', 'rightcolumn');
but when I try to load the content using XML i get this error:
"256 levels of recursion were exceeded in one action list.
This is probably an infinite loop.
Further execution of actions has been disabled in this movie.
"
What am i doing wrong???
Code:
import flash.external.*;
myXML = new XML ();
myXML.ignoreWhite = true;
myXML.onLoad = function (ok)
{
if (ok)
{
//process data
allGalleryData = this.firstChild.childNodes;
for (i = 0; i < allGalleryData.length; i++){
newLink=hold_mc.attachMovie("btn_mc","hold"+i,i);
newLink._y=(i*(newLink._height+4));
newLink.btn.name = allGalleryData[i].firstChild.firstChild;
newLink.btn.title = allGalleryData[i].firstChild.nextSibling.firstChild;
newLink.txt.text=newLink.btn.name;
newLink.btn.onPress=function(){
ExternalInterface.call("ajaxpage", this.title, 'rightcolumn');
}
}
}
}
myXML.load("link.xml");
ExternalInterface With IE?
Hey all,
I am working on a .swf that needs to get some information from a javascript on the HTML wrapper. I am using flash.external.ExternalInterface to call a javascript function called getProduct(). The function returns an object with 2 properties: id, and col, where col is an Array of hex color numbers.
Firefox and other mozilla based browsers love it, but IE doesn't work. Is there something I missed about implementing this in IE? See the code below:
javascript:
PHP Code:
var ProductID = 16; //Change this for every product
var colors = new Array();
colors.push("62480D");//BROWN
colors.push("FDCECE");//PINK
//Add another color here: colors.push("NEW HEX VALUE"); //NEW COLOR NAME
var Product = {id:ProductID,col:colors};
function getProduct() {
return Product;
}
Actionscript Class that calls the javascript function:
PHP Code:
import flash.external.ExternalInterface;
import flash.geom.Transform;
import flash.geom.ColorTransform;
class DataLoader {
var dataObj:Object;
var colorSwatches:Array;
var currentColor:Number;
function DataLoader() {
this.currentColor = 0;
this.colorSwatches = new Array();
this.dataObj = ExternalInterface.call("getProduct");
trace("PRODUCT:"+this.dataObj.id);
//A bunch of data manipulation here...
}
}
I have tried changing the datatype that the javascript returns to a simple string, because I thought perhaps IE didn't like that I was sending an Object, but that made no difference. I have also tried putting the javascript both inline, and as an include. The only thing I haven't tried, and that I can't do because of the nature of the project, is putting the javascript in the HTML <head> tag.
Any ideas?
Thanks in advance!
Andrew
ExternalInterface And XML?
I am creating links in my flash movie using XML. Once I do I would like the links to send info to my HTML page using ExternalInterface. It works when I hard code the url like so:
ExternalInterface.call("ajaxpage", 'hardCode.htm', 'rightcolumn');
but when I try to load the content using XML i get this error:
"256 levels of recursion were exceeded in one action list.
This is probably an infinite loop.
Further execution of actions has been disabled in this movie.
"
What am i doing wrong???
Code:
import flash.external.*;
myXML = new XML ();
myXML.ignoreWhite = true;
myXML.onLoad = function (ok)
{
if (ok)
{
//process data
allGalleryData = this.firstChild.childNodes;
for (i = 0; i < allGalleryData.length; i++){
newLink=hold_mc.attachMovie("btn_mc","hold"+i,i);
newLink._y=(i*(newLink._height+4));
newLink.btn.name = allGalleryData[i].firstChild.firstChild;
newLink.btn.title = allGalleryData[i].firstChild.nextSibling.firstChild;
newLink.txt.text=newLink.btn.name;
newLink.btn.onPress=function(){
ExternalInterface.call("ajaxpage", this.title, 'rightcolumn');
}
}
}
}
myXML.load("link.xml");
ExternalInterface
Doing a project where the flash player container is c++. The messages backward/forward to c++ works perfectly but apparently when the c++ send a lot of data the externalInterface goes down. My swf doesn't get anymore messages after that and I can't register a new callback.
So my question is, does externalInterface have some restrictions? Have anyone used it and had problem?
I can't really find that good documentation about it.
ExternalInterface - JS From Within Swf
Imagine I have an swf which needs to be able to be uploaded by anyone on any site. Imagine it is just this swf file which can be uploaded, no attached html file and no attached JS file. Thus it's just the swf file, everything needs to be done from there.
Is it possible to use Flash to actually embed javascript within the swf itself rather than the html?
Some said it's possible if you store the javascript file as one large string within flash, but wouldn't this first need to be sent to the html before reading? If so is it possible to just tell flash to target the html page the swf is currently embedded within?
I can't see how I could just read it into flash, because the string wouldn't be recognised as a javascript file.
Does anyone have any suggestions on how it would work?
To sum it up, I want to use javascript with flash, but I only want a .swf file to be required.
Thankyou for any help or information you can give.
Bug Of ExternalInterface (I Know Why Now)
ExternalInterface class is a good way to transfer date between flash and html. But I found a bug today.
In IE AS can activate html's JS function, but can never get the return value from it. Firefox have no problem.
I tried Adobe's sample application "IntrovertIM", the problem is the same
Is this a bug?
Source file: http://www.adamstudio.cn/lab/AsCallJs.rar
ExternalInterface
Here is a simple Flex sample. It complied fine and display fine.
When I click the button, It suppose to give me the alert message.
But it give me nothing.
Can anyone help?
Thanks,
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="
ExternalInterface And CSS
Hi everybody,
Lately I've been running into a problem where ExternalInterface won't function if the flash object happens to be in a div where the css style visibility = 'hidden'. Anybody else run into this problem? Anybody have solutions or workarounds?
Thanks in advance
robert
ExternalInterface?
Hi,
I have a flash file that used the ExternalInterface class to communicate
with the html page (with javascript)
What I need to do is use Javascript functions to control the flash file...
..this is all working, but i'm just looking for the best way to do one of
them....
I need a javascript function that grabs contents of a text box(in the flash
file) and returns it to the javascript function.
any ideas?
Cheers
Tim
Bug Of ExternalInterface
ExternalInterface class is a good way to transfer date between flash and html. But I found a bug today. In IE AS can activate html's JS function, but can never get the return value from it. Firefox have no problem.
I tried Adobe's sample application "IntrovertIM", the problem is the same
Is this a bug?
Source file: http://www.adamstudio.cn/lab/AsCallJs.rar
Renew
I tried many time, finally found where the problem is: The JS code to activate ActiveX!
If delete that code, insert the flash directly, everything is OK:
Player8,AS2: http://www.adamstudio.cn/lab/var/test/test_v8.html
Player9,AS3: http://www.adamstudio.cn/lab/var/test/test_v9.html
If have that code, error shows up in IE:
http://www.adamstudio.cn/lab/var/test/test_error.html
Although I found where the problem is, buy I don't know how to solve it. Active ActiveX and let AS get JS's return value at the same time. Any one have an idea?
All the source files: http://www.adamstudio.cn/lab/var/test/test.rar
Using ExternalInterface
I have a web page with a few timers on and added the JavaScript onbeforeunload method to warn users they may lose information if they navigate away from the page. However, if they haven't started a timer it would be better not to use this and so I have added the following to the Start button ActionScript
if (ExternalInterface.available) {
ExternalInterface.call("running");
}
My JavaScript is
function unloadMsg() {
msg = "You may have a timer running."
return msg;
}
function setUnload(on) {
window.onbeforeunload = (on) ? unloadMsg : null;
}
function running() {
setUnload(true);
}
However, it doesn't seem to be working. Can anyone give me an idea where I'm going wrong please?
Edited: 03/18/2008 at 03:52:46 AM by gandalf458
ExternalInterface
Simply, it's not working.
What happens is PHP and MySQL populate the list of all available songs to play. JavaScript creates the playlist when the user clicks the songs they want the when the user chooses to play a song, the url, artist, and song title are transferred to Flash via ExternalInterface.
The AS works in flash, but not when it's integrated with JavaScript.
Code for the .php file and .as file are provided.
Thanks for anyone's help.
Attach Code
PHP FILE
<?php
$conn = mysql_connect(edited for security);
mysql_select_db("masterdatabase", $conn);
$query = "SELECT * FROM `search` ORDER BY `bandname` ASC";
$result = mysql_query($query, $conn) or die(mysql_error());
$row_result = mysql_fetch_assoc($result) or die(mysql_error());
?>
<head>
<script type="text/javascript">
<!--
var playlist = new Array();
function changeBGWhite(song){
document.getElementById(song).style.backgroundColor = "#FFFFFF";
document.getElementById(song).style.color = "#000000";
};
function changeBGGray(song){
document.getElementById(song).style.backgroundColor = "#333333";
document.getElementById(song).style.color = "#999999";
}
function addToPlaylist(bandname, track, genre, album, url){
var song = new Array();
song[0] = bandname;
song[1] = track;
song[2] = genre;
song[3] = album;
song[4] = url;
playlist[playlist.length] = song;
document.getElementById("playlistTABLE").innerHTML = document.getElementById("playlistTABLE").innerHTML + "<tr><td>" + playlist[playlist.length-1][1] + "<button type='button' onmousedown='play("" +playlist[playlist.length-1][4]+"", "" +playlist[playlist.length-1][0]+"", "" +playlist[playlist.length-1][1]+"")'>Play</button></tr></td>";
}
function play(url, artist, song){
if(document['player2'].callPlaySound(url, artist, song)){
alert("it worked");
}else{
alert("somethings messed up");
}
}
-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>quary //-- Make Money From Your Music! //-- Kick Ass Player</title>
<link href="../<?php echo $css; ?>" rel="stylesheet" type="text/css" /><link rel="shortcut icon" href="images/favicon.ico" />
<link rel="shortcut icon" href="images/favicon.ico" />
</head>
<body>
<div style="margin:5px;">
<table style="font-size:10px; background:#e3e3e3; padding:10px; float:left;" cellpadding="0px">
<tr><td>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="550" height="50" id="player2" align="middle">
<param name="allowScriptAccess" value="always" />
<param name="movie" value="player2.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#e3e3e3" /><embed src="player2.swf" quality="high" bgcolor="#e3e3e3" width="550" height="50" name="player2" swliveconnect="true" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</td></tr>
<tr><td style="padding-left:5px; font-size:12px; font-weight:bolder; color:#000000;">
<span style="float:left; width:150px;">Artist</span>
<span style="float:left; width:150px;">Track</span>
<span style="float:left; width:150px;">Genre</span>
<span style="float:left; width:150px;">Album</span>
</td></tr>
<?php $num = 0; ?>
<?php do { ?>
<?php
mysql_select_db($row_result['bandnumber'], $conn);
$queryURL = "SELECT `url` FROM `songs` WHERE `number` = ".$row_result['songnumber']."";
$resultURL = mysql_query($queryURL, $conn);
$row_resultURL = mysql_fetch_assoc($resultURL);
?>
<tr><td>
<div style="float:left;" onmouseover="changeBGWhite('song<?php echo $num; ?>')" onMouseOut="changeBGGray('song<?php echo $num; ?>')" onMouseDown="addToPlaylist('<?php echo $row_result['bandname']; ?>', '<?php echo $row_result['track']; ?>', '<?php echo $row_result['genre']; ?>', '<?php echo $row_result['album']; ?>', '../<?php echo $row_resultURL['url']; ?>')">
<div class='topleft' id="song<?php echo $num; ?>" style="float:left;"><div class='topright'><div class='bottomright'><div class='bottomleft' style="padding:5px;">
<span style="float:left; width:150px;"><?php echo $row_result['bandname']; ?></span>
<span style="float:left; width:150px;"><?php echo $row_result['track']; ?></span>
<span style="float:left; width:150px;"><?php echo $row_result['genre']; ?></span>
<span style="float:left; width:150px;"><?php echo $row_result['album']; ?></span>
</div></div></div></div>
</div>
</td>
</tr>
<?php $num++; ?>
<?php } while ($row_result = mysql_fetch_assoc($result)); ?>
</table>
<table id="playlistTABLE" style="float:left; font-size:10px; background:#e3e3e3; padding:10px;">
</table>
</div>
</body>
</html>
ACTIONSCRIPT FILE
import flash.external.*;
var sound:Sound = new Sound();
function playSound(url:String, artist:String, song:String){
this.sound.loadSound(url, "true");
sound.start(0,1);
song_txt.text = artist + " - " + song;
}
play_btn.onRelease = function(){
sound.start(sound.position/1000);
}
pause_btn.onRelease = function(){
sound.position = sound.position;
sound.stop();
}
stop_btn.onRelease = function(){
sound.position = 0;
sound.stop();
}
prev_btn.onRelease = ExternalInterface.call("previousSong");
next_btn.onRelease = ExternalInterface.call("nextSong");
ExternalInterface.addCallback("callPlaySound", null, playSound);
ExternalInterface And XML?
I am creating links in my flash movie using XML. Once I do I would like the links to send info to my HTML page using ExternalInterface. It works when I hard code the url like so:
ExternalInterface.call("ajaxpage", 'hardCode.htm', 'rightcolumn');
but when I try to load the content using XML i get this error:
"256 levels of recursion were exceeded in one action list.
This is probably an infinite loop.
Further execution of actions has been disabled in this movie.
"
What am i doing wrong???
Code:
import flash.external.*;
myXML = new XML ();
myXML.ignoreWhite = true;
myXML.onLoad = function (ok)
{
if (ok)
{
//process data
allGalleryData = this.firstChild.childNodes;
for (i = 0; i < allGalleryData.length; i++){
newLink=hold_mc.attachMovie("btn_mc","hold"+i,i);
newLink._y=(i*(newLink._height+4));
newLink.btn.name = allGalleryData[i].firstChild.firstChild;
newLink.btn.title = allGalleryData[i].firstChild.nextSibling.firstChild;
newLink.txt.text=newLink.btn.name;
newLink.btn.onPress=function(){
ExternalInterface.call("ajaxpage", this.title, 'rightcolumn');
}
}
}
}
myXML.load("link.xml");
ExternalInterface And An LMS
I'm trying to achieve bookmarking through use ExternalInterface.call. I'm not getting the results I want. Here's my HTML:
Code:
//Alert user to bookmarking if returning
var oprompt;
function promptUser() {
if(api.LMSGetValue("cmi.core.lesson_status") != "not started") {
var x = window.confirm("You are returning from a previous attempt in this course. Would you like to return from where you left off?");
if (x) {
oprompt = api.LMSGetValue("cmi.core.lesson_location");
} else {
oprompt = 2;
}
} else {
oprompt = 2;
}
return oprompt;
}
Here's my FLA (frame 1) code:
Code:
//This is needed to make any calls to HTML/JS/LMS from Flash
import flash.external.*;
// --> Get bookmark from LMS
var prompt;
function getBkmk(){
//modstatus = ExternalInterface.call("api.LMSGetValue","cmi.core.lesson_status");
//bookmarkframe = ExternalInterface.call("api.LMSGetValue","cmi.core.lesson_location");
prompt = ExternalInterface.call("promptUser");
ExternalInterface.call("alert","oprompt = "+oprompt);
_root.gotoAndStop("main",oprompt);
/*if(modstatus == "incomplete"){
gotoAndStop(bookmarkframe);
}else{
gotoAndStop(2);
}*/
}
getBkmk();
I'm using the ADL Test Suite to test it, but I've also put it up on a devbox in my real LMS.
I think the problem is Flash is not receiving the "oprompt" variable.
Any thoughts?
ExternalInterface
I want to initialize a JS function when the swf loads. However, I can't seem to get it to return the value. What am I doing wrong?
ActionScript Code:
import flash.external.ExternalInterface;var sending_lc:LocalConnection = new LocalConnection();var thisresult:Object = ExternalInterface.call("initializedSend");received_ti.text = "Returned: " + thisresult;sending_lc.send("demoConnection", "printOut", thisresult);function getTextFromJavaScript(str:String):Void { received_ti.text = "From JavaScript: " + str; sending_lc.send("demoConnection", "printOut", "from JS: "+str);}ExternalInterface.addCallback("sendTextToFlash", this, getTextFromJavaScript);function clickSend(eventObj:Object):Void { var jsArgument:String = sending_ti.text; var myresult:Object = ExternalInterface.call("getTextFromFlash", jsArgument); received_ti.text = "Returned: " + myresult;}send_button.addEventListener("click", clickSend);
PHP Code:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><script language="JavaScript"> function getFlashMovie(movieName) { var isIE = navigator.appName.indexOf("Microsoft") != -1; return (isIE) ? window[movieName] : document[movieName]; } function formSend() { var text = document.htmlForm.sendField.value; getFlashMovie("ExternalInterfaceExample").sendTextToFlash(text); } function initializedSend() { document.htmlForm.receivedField.value = "From Flash: Intialized"; getFlashMovie("ExternalInterfaceExample").sendTextToFlash("it Worked"); } function getTextFromFlash(str) { document.htmlForm.receivedField.value = "From Flash: " + str; return str + " received"; }</script><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>ExternalInterfaceExample</title></head><body bgcolor="#ffffff"><form name="htmlForm" method="POST" action="javascript:formSend();"> Sending to ActionScript:<br /> <input type="text" name="sendField" value="<?=$_GET['var']?>" /> <br /> <input type="submit" value="Send" /><br /> <br /> Received from ActionScript:<br /> <input type="text" name="receivedField"></form><!--url's used in the movie--><!--text used in the movie--><!-- saved from url=(0013)about:internet --><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="800" height="600" id="ExternalInterfaceExample" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="ExternalInterfaceExample.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="ExternalInterfaceExample.swf" quality="high" bgcolor="#ffffff" width="800" height="600" name="ExternalInterfaceExample" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object></body></html>
ExternalInterface With C#
hey everyone. I am trying to use ExternalInterface in a C# wrapper. I can get ActionScript to talk to C#, but not the other way around. I know everyone is going to say I need to declare the ActionScript function first. Believe me, I did.
I also tried using the activeX dll files from 2003 to no avail.
I've seen other people with the same problem, but never a solution. It seems the only people who have gotten this to work BOTH ways are the people publishing from FLEX.
Is this just coincidence?
ExternalInterface
Hello everyone,
I am facing a problem , that ExternalInterface.callback works from document root but does not work when i call from within 2 movieclips deep.( movieclip inside a movieclip on the stage).
The function to register for callback is inside teh movieclip
can some one guide me please ?
Using ExternalInterface
Hi all
Having some problems with the new update of the flash player. Seems that getURL doesn't work and you have to use a new function. I am trying to get this to work but I am having trouble.
import flash.external.*;
ExternalInterface.call("firstNarrationCheck",pageN umber);
This is the code we have.
Problem is..
When you click on a button it needs to open another html window.
Yikes can someone help me please...
ExternalInterface
I keep getting the following error -
Error: obj.getUserID is not a function
FLASH
Code:
import flash.external.*;
ExternalInterface.addCallback("getUserID", getUserID);
function getUserID():Number
{
return '13';
}
JS
Code:
$(document).ready(function() {
var obj = swfobject.getObjectById("cookieMe");
alert(obj.getUserID());
});
I cant figure out for the life of me where to start or what is wrong, any help is appreciated.
Thanks
carn
Using ExternalInterface To Pass AS -> JS
I'm trying something different, seems like ExternalInterface API might be my answer to send a button name to my form POST.
In my SWF for my button I have this:
Code:
set ("buttonPressed", "pest");
import flash.external.ExternalInterface;
// Register so that it is possible to call from JavaScript in containing HTML
ExternalInterface.addCallback("getBtnName", null, getBtnName);
submitBtn.addEventListener("click", clickListener);
function clickListener(eventObj:Object):Void {
ExternalInterface.call("getFlashBtn", buttonPressed);
getURL("javascript:flashFormSubmit();");
}
getFlashBtn() is a function in my html form page:
Code:
var foo = null;
function getFlashBtn(btnname) {
foo = btnname;
}
function flashFormSubmit()
{
var myForm = document.forms[0];
var bn = document.getElementById('bname');
bn.value = foo;
myForm.submit();
}
as you can see I then send the buttonname that was supposedly sent by AS to a textfield, and then post the form using getUrl() with my js function.
Problem is, my form is not submitting. It seems the eventlistener is not firing. "submitBtn" is the instance name of my button. I'm not sure what is wrong, any ideas?
Tom
ExternalInterface.call
I am hoping someone can offer some advice on this. Sorry to ask this basic of a question but there is absolutely no one locally I can ask and I am trying to learn the hard way (no advise or assistance).
I am trying to send a JavaScript command (JavaScript:returnClientValue('QuizInfoURL')) to a php page ( classdev.pyxis.com/scripts/courseGetQuizDetails.php) using the ExternalInterface.call
I am also trying to assign anything received back from the php page to the variable (testStr).
I have a book (ActionScript 2.0 Garage) that I am referencing and it says that this should work.
Here is the code I am using:
---------------------------
on(release){
var testStr:String = ExternalInterface.call("classdev.pyxis.com/scripts/courseGetQuizDetails.php","JavaScript:returnClient Value('QuizInfoURL')")
ExternalInterface.call("classdev.pyxis.com/scripts/courseGetQuizDetails.php","JavaScript:returnClient Value('QuizInfoURL')")
}
----------------------------
Any help will go a long way.
Thanks
The ExternalInterface Blues...
Hey guys,
I'm trying to use ExternalInterface to communicate from JavaScript to ActionScript. Everything is working properly in all browsers with the exception of Internet Explorer. Check it out at http://www.theradi.us.
Here is the ActionScript code:
Code:
import flash.external.ExternalInterface;
//-----this is called when the 'Go' button is pressed-------------------------
ExternalInterface.addCallback("goClick", this, goClick);
function goClick():Void
{
DoSearch();
}
All of the JavaScript is in the page source at theradi.us. The error that I am getting in IE is a JS error when the page is loaded. "Line: 1 Char: 1 Error: 'header' is undefined."
This one has been eating at me for days... any help would be GREATLY appreciated!
Thanks,
G
ExternalInterface Problems
Hi.
I've tried using ExternalInterface class in Flash 8 to control some movie behaviour with JavaScript. I did exactly what docs say (see here ) but it didn't work. Javascript (in both IE and FF) says that the object does not have such method or smth.
I also tried to run both External API samples provided with flash studio and also no success - the same errors. What i'm doing wrong?
Help Return Value From ExternalInterface
adobe's site is only posting examples for ExternalInterface, which
return values inside of a function.
this works
Code:
import flash.external.ExternalInterface;
ExternalInterface.addCallback("asFunc", this, xasFunc);
function xasFunc(str:String):Void {
_root.testVal.text = str;
}
but instead of using the "str" variable inside of the function, i would
rather return the result, so i can use the "str" variable outside of
the function. this is the style code i would like to apply, but it does not work.
Code:
import flash.external.ExternalInterface;
ExternalInterface.addCallback("asFunc", this, xasFunc);
function xasFunc(str){
return str;
}
xresult = xasFunc(str);
_root.testVal.text = xresult;
how can i get the value of "str", but use it outside of the function ???
ByteArray And ExternalInterface
Hi,
I have a bitmap data which I can convert to a byteArray and then encode to a png or jpg. In Apollo i can save the png to disc.
I now need to do the same in a C# desktop application. I have used externalInterface to communicate between flash and the c# but it serialises all data as XML and cannot serialise a byteArray. I have seen examples that use AMF or a socket to communicate with a server but I dont think method will work for communicating with a desktop app. Is there any way of converting a byteArray into a string to be send to the c# and decoded?
Or is there any other method?
help on this would be much appreciated as i am v. curfudled
ExternalInterface Hack:possible?
Is there any way to see the communication between a swf and the javaScript of the site he is in?Assuming flash will do it using ExternalInterface?
Thankzz
[F8] ExternalInterface Not Working :-(
...and Flash is not providing any clues as to why not!
I'm publishing to Flash 8, AS2.
In main timeline I have inserted this:
import flash.external.* ;
on a button, later in the movie, I put this:
Code:
on(release){
ExternalInterface.call("sendMessageToVT", "erwerwerwerewr");
}
That doesn't seem to do anything. The button is NOT inside a clip or anything. Does it have to be named? What am I doing wrong?
I know the function works, because it echoes back the data when I use the old getURL method of calling JS.
What are the cons of resorting to old getURL method? I'm afraid I'll have to if I can't sort out ExternalInterface.
PS: I tested Macromedia's own example and it works fine. YES I know it must be uploaded to server to work.
Thanks
ExternalInterface Problem...
Hi...don't know if this has been asked before...Two questions, really:
(1) I'm using an AJAX-like method to load the body of an HTML page into a DIV. The HTML page contains an AS3 movie that's loaded w/ AC_RunActiveContent.js ...but it won't load when inserted into a DIV this way. I don't get it, b/c other JS on the insert seems to work. I'm using an .innerHTML in JS to include the page.
(2) Even when I just use only object tags and the flash movie does show up in the DIV, Flash believes that ExternalInterface.available==false. I can't figure this one out at all.
Any help would be greatly appreciated!
ExternalInterface - Javascript
HI there.
I have followed the tutorials and I can get the basics, pass form fields back and forth between browser and flash to work fine.
The problem I have though, is that I have to pass the value of 2 variables from flash:
"price" (a number) and
"buyerType" (either "ftbnh", "ftbrh" or blank)
to a javascript function called "MCGetOntarioLTT" which then needs to take those two values, run a caculation and send the result back to the flash movie to be displayed.
I can get an html form to display data sent from flash, but can anyone offer any help as to how to tell flash to simply send the 2 values, run the javascript function and then send the result back to flash to be displayed without displaying anything in the html?
The javascript function, "MCGetOntarioLTT" is also a remote javascript function that I have no control over.
I am in over my head here and any advice or nods in the right direction would be greatly appreciated.
Cheers
[CS3] ExternalInterFace Not Working
Hi My head is rotating because of this code....
there this is my flash code
But problem is External interface is not working.....
import flash.external.*;
var array:Array = Array("New Limpopo Province.swf","New Gauteng.swf","New Mpumalanga.swf","New North West Province.swf","New Kwazulu Natal.swf","New Free State.swf","New Eastern Cape.swf","New Western Cape.swf","New Northern Cape.swf");
numCountry = 20;
mov = _root.createEmptyMovieClip( "movie", _root.getNextHighestDepth());
i = 1;
while (i < numCountry)
{
newName = "a" + i;
var Depth:Number = new Number(0);
eval(newName).onRollOver = function()
{
Depth = this.getDepth();
this.swapDepths(2);
var __reg2 = new mx.transitions.Tween(this, "_xscale",regular.easeOut, this._xscale, 150, 1, true);
__reg2 = new mx.transitions.Tween(this, "_yscale",regular.easeOut, this._yscale, 150, 1, true);
this.gotoAndStop(2);
};
eval(newName).onRollOut = function ()
{
this.swapDepths(Depth);
var __reg2 = new mx.transitions.Tween(this, "_xscale", regular.easeOut, 150, 100 , 1, true);
__reg2 = new mx.transitions.Tween(this, "_yscale", regular.easeOut, 150, 100 , 1, true);
this.gotoAndStop(1);
};
eval(newName).onRelease = function ()
{
/********** the code here is showing
External interface not working***********/
var isAvailable:Boolean = ExternalInterface.available;
if(!isAvailable){
logo._visible = false;
}
_root.ExternalInterface.call("as");
/************************************************** ***/
for( count = 0 ; count < numCountry ; count++ )
{
Name = "a" + count;
eval(Name)._visible = false;
}
for( count = 0 ; count < numCountry ; count++)
{
Name = "b" + count;
eval(Name)._visible = false;
}
file = parseInt(this._name.substr(1,1));
//mov = "image"+this._name ;
mov.loadMovie( array[ file - 1 ] );
};//"http://devserver/prototype/modules/mod_flash/"+
++i;
}
logo.onRelease = function(){
mov.unloadMovie();
for( count = 0 ; count < numCountry ; count++ )
{
Name = "a" + count;
eval(Name)._visible = true;
}
for( count = 0 ; count < numCountry ; count++)
{
Name = "b" + count;
eval(Name)._visible = true;
}
}
My javacode is :
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>New South Africaa</title>
</head>
<body bgcolor="#ffffff">
<!--url's used in the movie-->
<!--text used in the movie-->
<!-- saved from url=(0013)about:internet -->
<script>
function as()
{
alert("yjid t");
return 0;
}
</script>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="1024" height="768" id="New South Africaa" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="New South Africaa.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /> <embed src="New South Africaa.swf" quality="high" bgcolor="#ffffff" width="1024" height="768" name="New South Africaa" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>
</html>
PLEASE HELP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! : mario:
Externalinterface Nightmares: AS3
Hello,
I do not know why I am having so much trouble with using the externalinterface and attempting to have javascript call an actionscript function when the browser window is in focus.
The plan is, as the client requested, to have a popunder box pop up when the user first visits the client site. Then I have a video on the popunder box that they client would like to start playing as soon as the popunder box is the browser window in focus.
I am able to use the externalinterface to grab the url of the container page... but that is it.
Here is my flash script:
Code:
if (ExternalInterface.available) {
try {
ExternalInterface.addCallback("plathevideo", playitnow);
if (checkJavaScriptReady()) {
output.appendText("JavaScript is ready.
");
}
else {
output.appendText("JavaScript is not ready, creating timer.
");
var readyTimer:Timer = new Timer(100, 0);
readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
readyTimer.start();
}
}
catch (error:SecurityError) {
output.appendText("A SecurityError occurred: " + error.message + "
");
} catch (error:Error) {
output.appendText("An Error occurred: " + error.message + "
");
}
}
else {
output.appendText("External interface is not available for this container.");
}
function checkJavaScriptReady():Boolean {
var isReady:Boolean = ExternalInterface.call("isReady");
return isReady;
}
function timerHandler(event:TimerEvent):void {
output.appendText("Checking JavaScript status...
");
var isReady:Boolean = checkJavaScriptReady();
if (isReady) {
output.appendText("JavaScript is ready.
");
Timer(event.target).stop();
}
}
Here is the javascript:
Code:
<script type="text/javascript">
function onBlur() {
};
function onFocus(){
BeeWindows.plathevideo();
};
if (/*@cc_on!@*/false) { // check for Internet Explorer
document.onfocusin = onFocus;
document.onfocusout = onBlur;
} else {
window.onfocus = onFocus;
window.onblur = onBlur;
}
</script>
Here is my flash content:
Code:
<div id="flashcontent">
</div>
<script type="text/javascript">
var so = new SWFObject("../flash/popupplayer.swf", "BeeWindows", "300", "300", "9", "#FFFFFF");
<!--- still shot -->
so.addVariable("stillshot", "../flash/pam.png");
<!--- flv url --->
so.addVariable("videofile", "http://fathomseo.cachefly.net/clients/freewebmc/beewindow/2.flv");
<!--------- color in hex value 0xFFFFFF ----------->
so.addVariable("thecolor", "0xBB4C5F");
so.addParam("wmode", "transparent");
so.useExpressInstall('http://www.fathomseo.com/videoftp/clients/freewebmc/flash/expressinstall.swf');
so.write("flashcontent");
</script>
I have been trying to use basic scripts I find on the internet and try to follow along with the logic. That is where I got my flash script.
If anyone can point me in the right direction or show me what I am doing wrong I would once again be in debt to the flashkit community. My client has been bugging me about this and I cant wait to figure it out.
Thanks!
ExternalInterface Not Returning A Value
I created a little sample app using externalinterface's call function to call a javascript function and return a value, but it keeps returning null. Any ideas?
Js function
Code:
function getLocation() {
return window.location.toString();
}
Code:
import flash.external.ExternalInterface;
data.text = ExternalInterface.call("getLocation");
Pretty much as plain as it can be. Any ideas?
Help Trying To Load Js With ExternalInterface
I think I'm close to figuring this out. But I still can't get it to work.
I am trying to call a 3rd party js file to run a script display their content on my site.
In my actionScript I am trying to use the externalInterface. I have a javascript file and html page that the flash lives on, but they are all not talking to each other.
I attached all my files. It seems like it should be easy..but I am not a programmer.
This is the link that works great on an html page.
HTML Code:
<script language="javascript" src="http://www.bankrate.com/aff/jsfeeds/aff-mtg.js"></script>
this is the site I am trying to get it to run on. (bottom left corner it should display)
http://www.schrieberrealty.com
ExternalInterface Problem In IE
Hi!
I'm using ExternalInterface to communicate between AS and Javascript, and this works fine.
However, after I hide and show the div-tag containing the Flash-movie (to show an image), this stops working in Internet Explorer. The communication dies...
Anyone knows why this happens?
Regards,
Foxtrot
Why Isn't This ExternalInterface Working?
I have been trying to use ExternalInterface to record "pages" in my flash site so I can see stats of them in google analytics. For the most part I have been doing this using the following:
ExternalInterface.call("urchinTracker('/main/stock')");
This is working fine. My problem is when I want to dynamically create the path name. I have used the following code but it is not working.
page = "'/"+button+"'"; //button is a variable which holds different strings
tracker = ""urchinTracker("+page+")"";
ExternalInterface.call(tracker);
Anyone spot what I am doing wrong?
Thanks
Onbeforeunload & ExternalInterface
Dear all,
I am writing a web application in Flash 8 that runs in a browser. I need to catch if a user leaves the site, as he is playing an online game with other users. If he leaves, he must be deleted from the userlist. Thus, I try to catch the person leaving the site with the Java onbeforeunload event. In that event, I call an Actionscript funtion. But that doesn't seem to work. Onbeforeunload is called, but the Actionscript function I am trying to access from there is never called or stalls - the browser never gets to the return part of the Javascript where usually a confirmation window pops up. If I don't call Actionscript, Javascript does give me that popup window. Can you help me identify the problem?
The html page:
HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Risk Online by Heinzel</title>
<script language="JavaScript">
var flash;
window.onload = function() {
if(navigator.appName.indexOf("Microsoft") != -1) {
flash = window.flashObject;
}else {
flash = window.document.flashObject
}
}
window.onbeforeunload = function() {
flash.getFlashInfo();
return "If you are currently in a game, other players will miss you!";
}
</script>
</head>
And the follwing Actionscript is on top of frame 80 in my Flash movie, which is the frame where gameplay takes place:
Code:
import flash.external.ExternalInterface;
function getFlashInfo() {
riskSocket.send("chat,"+_global.gameid+","+namedisplay_txt.text+": Ich verlasse das Spiel
");
}
ExternalInterface.addCallback("getFlashInfo", this, getFlashInfo);
I doubt that the Socket call is a problem because it is correct syntax, used elsewhere just like this. Also, if I comment it out and put some other command in there, nothing happens either.
Your help is greatly appreciated!
heinzel
ExternalInterface Question
I NEED HELP!
Here is what I'm trying to do. I have 3 external .js files that I am trying to reference from within actionscript to create a "lightwindow" to display whatever media i wish. I have Flash CS3 but i'm NOT using AS3. So Far I have this in the HTML page that has flash embedded :
<script type="text/javascript" src="javascript/prototype.js"></script>
<script type="text/javascript" src="javascript/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="javascript/lightWindow.js"></script>
<link rel="stylesheet" href="css/lightWindow.css" type="text/css" media="screen" />
In the flash document I have this actionscript to try and call the .js function "lightwindow" to open the "lightwindow":
import flash.external.ExternalInterface;
myBut.onPress = function() {
if (ExternalInterface.available) {
ExternalInterface.call("lightwindow","http://www.jestercom.com");
}
};
stop();
I am using the "Light Window v2.0" program and the website is http://stickmanlabs.com/lightwindow/ if you need reference. I am intermediate with actionscript so if i'm making a stupid mistake that's why but i can't figure out why this isn't working. If someone can figure out a way to do this more efficiently or simply correctly please let me know. Also if one can reference the .js files without putting the code in the html page that would be great too...but i'll take whatever i can get. Thanks in advance.
How Does One Get Arrays Using ExternalInterface?
I've been able to get variables from javascript using the ExternalInterface class, but i cant seem to get arrays into actionscript. Can anyone show me an example of how to deal with arrays passed from javascript? Im working toward bringing in a multidimensional array.. but im trying to get a 1-dimensional to work first...
thanks
ExternalInterface.addCallback
This is my js code.
Code:
function Test {
var flash_element = CreateFlashDIV(PATH_TO_FLASH);
elements[i].parentNode.appendChild(flash_element);
this.flashObj = getFlash(id);
this.flashObj.test();
}
Test.prototype.test = function() {
this.flashObj.test();
}
Here CreateFlashDIV adds a flash element to the div based on pathtoflash.
and getFlash returns a flash object. These functions work properly and have been tested.
Now test is a function which I register in my main application class in AS code.
The problem is if I call this.flashObj.test(); in the constructor i get an error saying the test() function is not defined.However when I call Test.test() when a button is clicked it all works like a charm. It seems that the AS3.0 takes some time to register the callback and hence calling the test method immediately after creating an instance of the flash object doesnot work.
Is my guess correct and how can I make the this.flashObj.test(); work in constructor.
ExternalInterface Question
Hello all!
I'm wondering if anyone has come across this yet. I'm trying to get a swf to communicate with an LMS. Back in as2 I would use fscommand, but from what I've read is the ExternalInterface is used in as3 to talk to js files. Here is the code that I'm using to try to get the course to close out.
ActionScript Code:
finishButton.addEventListener(MouseEvent.CLICK,finishCourse);
function finishCourse(me:MouseEvent) {
var lFinish:String = "LMSFinish()";
var setV:String = "LMSSetValue";
var setL:String = "cmi.core.lesson_status,complete";
ExternalInterface.call("LMSSetValue",setV,setL);
ExternalInterface.call("LMSFinish",lFinish,"");
}
I tried closing a window through javascript and it worked using this:
ActionScript Code:
var myWindow:String="javascript:self.close()";
ExternalInterface.call("closewindow",myWindow);
Can anyone point me in the right direction? Thanks
ExternalInterface In Actionscript 2.0
Hi there,
I wish someone can help me. I hope to get my flash project to run in Flash CS3 with actionscript 2.0.
There are some functions like "ExternalInterface.call(...)" that I am trying to call.
I added
import flash.external.ExternalInterface;
But it still does not work.
Thank in advance.
ExternalInterface Issues In IE 7
I've scoured the forums and the internet, and implemented all the suggestions that I could find, but for some reason I still an unable to get IE to properly receive the return value from my javascript. I have simple actionscript, ripped from the programming manual:
ActionScript Code:
if (ExternalInterface.available) {
trace("external interface is availabe");
var containerReady:Boolean = isContainerReady();
if (containerReady)
{
setupCallbacks();
}
else {
var readyTimer:Timer = new Timer(100);
readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
readyTimer.start();
}
}
where isContainerReady is simply:
ActionScript Code:
private function isContainerReady():Boolean {
var result:Boolean = ExternalInterface.call("isReady");
trace("isContainerReady: " + result);
return result;
}
I then have a simple html page:
HTML Code:
<script type="text/javascript">
function loadXML(url) {
thisMovie("player").parseXML(url);
}
function isReady() {
return true;
}
function thisMovie(movieName) {
if (navigator.appName.indexOf ("Microsoft") !=-1) {
return window[movieName];
}else {
return document[movieName];
}
}
</script>
<body onload="pageInit();">
<object id="player"><embed src="soundPlayer.swf" id="player" quality="high" scale="exactfit" width="450" height="450" name="player" align="middle" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/></object>
test player
This is a <a onClick="loadXML('file:///C:/general%20fuzz/soulful%20filling/partails/fuzzy%20prayer/mp3s/fuzzyprayer3.xml')"; href="#">link</a>
</body>
using javascript alert, I see that isReady() is being executed by the flash app. The problem is that in IE 7, the value received by ExternalInterface.call("isReady") is false. In firefox its true. I have no idea how to get around this issue for IE, and I'm going a bit batty. Any help would be most appreciated
Thanks,
GF
Ie Get Data From Js Using ExternalInterface
Hi All
I need to get some data back from js, really just need it to read a cookie. this works in every browser but ie. Its driving me nutts I cant seem to find a way to make this work. I cant use flash shared object I need to be able to read a cookie that has already been set.
ActionScript Code:
import flash.external.*;
var greeting:String;
getCookie("imgName")
function getCookie(cookieName:String) {
greeting = String(ExternalInterface.call("getCookie", cookieName));
this.getTxt.text = greeting+" "; // >> Hi Flash.
}
stop()
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Actionscript Javascript Communication from Circlecube</title>
<script language="javascript" >
function getCookie(cookieName) {
return "sd "+get_cookie(cookieName);
}
function get_cookie ( cookie_name )
{
var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
if ( results )
return ( unescape ( results[2] ) );
else
return null;
}
</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<div align="left">
<embed src="getCookie.swf" id="flash" quality="high" scale="exactfit" width="450" height="450" name="squambido" align="middle" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/> </div></td>
</tr>
</table>
</body>
</html>
|