Вопрос

Is it possible to use Actionscript 3 file reference from javascript. I need to code an application that will use javascript to call the browse method of the fileReference.

I wanted to be sure this is possible before I put too much time into the code. I did not know if there were some security issues there.

Это было полезно?

Решение

You can call anything you want defined in AS3 from Javascript. The thing is, you won't be able to directly use the FileReference object in your Javascript, but you can write all the methods you need in Actionscript, and then call them when needed. So AS3 would be something like a data provider.

Let me know if you need some code examples. If you're new to this check out ExternalInterface.

Edit:

So do you want to load the .mp3 from Flash side or from JS? If you want to use a FileReference I guess it's from Flash. Anyway, Flash will need to have the .mp3, as a ByteArray or as a link to it, so it can then load and play the sound.

Basically you need to make everything Flash sided. I mean the actual volume, play/pause and other functionality should be implemented on the Flash side, but controlled from Javascript.

You can add callbacks for methods in Flash, so that afterwards you can do something like this from javascript:

flashObject.playMusic();

On the Flash side you would need to write something like this:

if(ExternalInterface.available) {
    ExternalInterface.addCallback("playMusic", playMusic);
}

function playMusic():void {
    musicObject.play();
}

So what we do here is, add a callback to a Flash object, so that playMusic method can be called from Javascript, then define our actual method for playing the sound object. You can pass and get parameters like you'd do normally.

Keep in mind to set the allowScriptAccess parameter of the Flash object in HTML to always.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top