SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Nov 2005
    Location
    Midwest
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    SitePoint Evangelist hexburner's Avatar
    Join Date
    Jan 2007
    Location
    Belgium
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First, let's see how you call a JavaScript alert:
    Code JavaScript:
    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:
    Code Actionscript:
    getURL("javascript:alert('Hello, world...')"); // mind the quotes again
     
    // Or
    var my_message:String = 'Hello, world...';
    getURL("javascript:alert('"+my_message+"');");
    FOR SALE: 1 set of morals, never used, will sell cheap

  3. #3
    SitePoint Guru
    Join Date
    Nov 2005
    Location
    Midwest
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  4. #4
    SitePoint Guru
    Join Date
    Nov 2005
    Location
    Midwest
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  5. #5
    SitePoint Evangelist
    Join Date
    Jan 2006
    Location
    UK
    Posts
    537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  6. #6
    SitePoint Guru
    Join Date
    Nov 2005
    Location
    Midwest
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  7. #7
    SitePoint Wizard jim_morrison3's Avatar
    Join Date
    Apr 2004
    Location
    UK
    Posts
    2,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TryingToLearn View Post
    So most people test Flash with ActionScript by publishing the Flash file to a .SWF and then load the .SWF into their web environment?
    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.

    Quote Originally Posted by TryingToLearn View Post
    It seems like there would be a more efficient way to test the ActionScript.
    You can always use trace() for that.
    Good Luck!
    There are things known and Things unknown
    And in between are the Doors.
    I love hand Coding.

  8. #8
    SitePoint Guru
    Join Date
    Nov 2005
    Location
    Midwest
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the response.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •