Do JavaScript alert from Flash using ActionScript

Hello

I am not a Flash expert (not even close) and I am trying to do something very basic. I want to display an alert message like I would do from JavaScript using ActionScript.

Here is what I have tried but neither of example works.

getURL(“javascript:alert(my message)”);
trace( “my message” );

When I run the getURL code from Flash using the Publish to HTML, when I click my button, nothing happens.

Can someone let me know if it is possible to have ActionScipt provide an alert message like someone would do from JavaScript? If possible, could you also provide a basic example?

Thanks you in advance for your time and knowledge.

First, let’s see how you call a JavaScript alert:

alert('Hello, world...'); // mind the quotes

// or
var my_message = 'Hello, world...'; // set the variable my_message
alert(my_message); // no quotes here

So, if you want to alert a message from ActionScript:

getURL("javascript:alert('Hello, world...')"); // mind the quotes again

// Or
var my_message:String = 'Hello, world...';
getURL("javascript:alert('"+my_message+"');");

Thank you for the post. I copied and pasted your example into the ActionScrit and it does not work. I am using ActionScript 2.0. Is there something else I need to check to see why this is not working? Any other ideas?

My problem may be with how I am testing the ActionScript in Flash. I ended up publishing the Flash file to an .SWF and ran it in my local web environment. Everything worked perfect. But I still can not get the ActionScript to alert the message in Flash. Should I be able to? If so, how do I do it?

No, because when you are testing in Flash you are playing back the swf inside the flash player not a browser. The browser has javascript, the swf player does not.

So most people test Flash with ActionScript by publishing the Flash file to a .SWF and then load the .SWF into their web environment? It seems like there would be a more efficient way to test the ActionScript.

Yes but since in your case you’re calling something which is not a part of Flash then you do need test your application in a browser.

You can always use trace() for that.

Thank you for the response.