2

I am very new to both JavaScript and ActionScript. I am trying to get javascript to call a function in ActionScript and store the returned array. I have looked everywhere for help and i cant seem to get this to work. My actionscript is below:

import flash.display.Sprite;
import flash.text.Font;
import flash.text.FontType;
import flash.text.FontStyle;
import flash.external.*;

public class FontList extends Sprite
{

    public function FontList()
    {
        ExternalInterface.call('populateFontsList', getDeviceFonts());
        ExternalInterface.addCallback('getFonts', getDeviceFonts);
    }

There is a getDeviceFonts() method that works, and the .call function works too, calling the function within the javascript. However, when i try and call the getFonts method in javascript it dosent work. Relavent Javascript is as below:

function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
}

var fontArray = getFlashMovie("FontList.swf").getFonts();

Am i missing something here?

1 Answer 1

3

If the Actionscript function getDeviceFonts() returns an array, your code should work as it is, and the fontArray in JavaScript would contain the same values.

One thing to keep in mind though is that you can't call the ActionScript function until it the swf file is loaded and ready, so for example, you can't do var fontArray = getFlashMovie("FontList.swf").getFonts(); directly on page load, since the swf won't be loaded yet, and hence getFonts() won't be defined yet.

But I guess ExternalInterface.call('populateFontsList', getDeviceFonts()); should work, if you have a JavaScript function populateFontsList that takes an array as an argument. That JavaScript function should be called as soon as the swf is loaded and the ActionScript is executed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.