Listen to the value of a var continuously

57 views Asked by At

I have a swf embedded in another application (Articulate Storyline), and I am using ExternalInterface to retrieve values from this application like so:

stop();

import flash.external.ExternalInterface;

var myFlashVar:Number = ExternalInterface.call('GetPlayer().GetVar',"myStorylineVar");

if (myFlashVar == 1) {
    play();
}

This all works fine, but I would like to know how I continuously listen to the value of "myStorylineVar" so that when it changes, I can perform my actions.

Thanks a lot!

1

There are 1 answers

3
Crabar On

Using ExternalInterface you can also call AS functions from JS code. I think it helps you. Some example:

// as3
ExternalInterface.addCallback("myFunction", myFunctionCallback);

function myFunctionCallback(someArg:String):void {
    doStuff();
}

// js
<script language="JavaScript"> 
    var callResult = flashObject.myFunction("someValue"); 
</script>

Documentation.

So, in your case, when value in js changed you can just call some as3 function and perform actions that you need.