Skip to main content
Inspiring
December 22, 2010
Answered

AS3 and Java

  • December 22, 2010
  • 1 reply
  • 1630 views

I have a javascript file with this function.

function getPageNumber()
{
var currentScoPage = doLMSGetValue(“cmi.core.lesson_location”);
    alert(‘getPageNumber - Value: ’ + currentScoPage);
<span style=“white-space: pre;”>  </span>document.getElementById(“testSWF”).SetVariable(“currentScoPage”, currentScoPage);
};

I have this code in a flash file.

var testing:String = ExternalInterface.call(“getPageNumber()”);

For some reason, the java alert popup shows the correct value but the flash var testing keeps coming up null.
What am I doing wrong?

This topic has been closed for replies.
Correct answer kglad

OK, I've simplified the situation in order to find an answer.

My javascript code:

var currentScoPage = 'test123';

function getPageNumber()

{

    alert('getMyPageNumber - Value: ' + currentScoPage);

    return document.getElementById("testSWF").SetVariable("currentScoPage", currentScoPage);

}

function savePageNumber(currentScoPage1)

{

     alert('savePageNumber - Value: ' + currentScoPage1);

     currentScoPage = currentScoPage1;

}

My Flash code:

function btnPush(e:MouseEvent)

{

     flash.external.ExternalInterface.call("savePageNumber", "c1p1");

     public var globalVar:String = ExternalInterface.call("getPageNumber", "currentScoPage");

     testInstance.textBox.appendText(globalVar + "-----");

}

The correct values are shown when the alert commands are triggered in the javascript.

But when the flash function is run, the testInstance.textBox shows null-----.


no, use:


My javascript code:

var currentScoPage = 'test123';

function getPageNumber()

{

    alert('getMyPageNumber - Value: ' + currentScoPage);

    return currentScoPage;

}


My Flash code:

function btnPush(e:MouseEvent)

{

     public var globalVar:String = ExternalInterface.call("getPageNumber");

     testInstance.textBox.appendText(globalVar + "-----");

}

1 reply

kglad
Community Expert
Community Expert
December 22, 2010

1.  java is not the same as javascript

2.  your call() method should be:

var testing:String = ExternalInterface.call(“getPageNumber”);

3.  the reason for your issue is you're probably not refreshing the variable that's storing your flashvar or you have a javascript error.  (do you have an element with id= "testSWF"?)

Inspiring
December 22, 2010

kglad,

1.  I apologize for my ignorance.  I now know I should of said javascript in both instances.  I am new to the entire javascript world.

2.  Since posting the first post I've found out there is a variable titled currentScoPage that the getPageNumber function accesses.

Does that mean

var testing:String = ExternalInterface.call(“getPageNumber”);  should actually be

var testing:String = ExternalInterface.call(“getPageNumber”,"currentScoPage"); ?

3a.  How do you refresh a variable in flash?  I wasn't aware that flash variables required refreshing.

3b.  If I was having a javascript error, how would I find out?

3c.  Yes I do have an element with id= "testSWF" in the HTML SWFObject.

          html code:

               var so = new SWFObject("shell.swf", "testSWF", "1000", "525", "8", "#000000");

Thanks for your help.

kglad
Community Expert
Community Expert
December 22, 2010

what are you trying to do?

are you trying to pass a value from flash to javascript so you can use it in your javascript?  or are you trying to pass a value from javascript to flash?  or, are you trying to do both?