Trigger Javascript functions from Flash AS3

February 4th, 2010

Using the ExternalInterface in AS3 it’s never been easier to trigger Javascript functions on your page that holds your swf.
Previously with AS2 and below We would have used the getURL(”javascript:yourFunction();”) or
fscommand(”messagebox”, “Message box called from within Flash.”)

I was asked on the forums today how this would be done in AS3.

After quickly looking up ExternalInterface in the flash Doc’s I was able to through together a quick working example.
A working example can be seen here.

Here is the code:

  1. // import classes we need
  2. import flash.external.*;
  3. import flash.net.*;
  4. //Make sure buttons show mouse over
  5. but1.buttonMode=true;
  6. but2.buttonMode=true;
  7. but3.buttonMode=true;
  8. //Added mouse event to buttons
  9. but1.addEventListener(MouseEvent.MOUSE_DOWN,triggerJavascript,false,0,true);
  10. but2.addEventListener(MouseEvent.MOUSE_DOWN,triggerJavascript,false,0,true);
  11. but3.addEventListener(MouseEvent.MOUSE_DOWN,triggerJavascript,false,0,true);
  12.  
  13. //Function to be triggered by mouse event
  14. function triggerJavascript(e:Event) {
  15. //check name of button pressed
  16. switch (e.target.name) {
  17. case "but1" :
  18. //open url in fixed size popup
  19. ExternalInterface.call("openPopup", "http://www.innovativedesigns.org.uk");
  20. break;
  21. case "but2" :
  22. //open url in new window
  23. ExternalInterface.call("openURL", "http://www.innovativedesigns.org.uk");
  24. break;
  25. case "but3" :
  26. //trigger javascript alert box
  27. ExternalInterface.call("triggerAlert", "Alert was triggered from Flash");
  28. break;
  29. }
  30. }
Download Trigger javascript from Flash AS3 Version V0.1
Bookmark and Share

DOPE Awards html site goes live

November 20th, 2009

logoFor the past couple of months I’ve been working very hard converting the current DOPE Awards.com flash site over to HTML. That’s not to say the Flash site is going to disappear this is more to improve SEO with the site. The main aspect of this project was to have the html version of the site as near identical of the flash site.  Looking at the DOPE Awards html version of the site i think it’s pretty close and I hope you think so to.

Coming from a flash background of 8+ years this certainly was going to be a challenge. Well a few months later and it is finished. The site fully conforms to W3C and is also cross browser compatible on most popular browsers and even IE8.

Dope Flash website awards

Dope Flash website awards

Be sure to check out DOPE Awards.com as there is some great new features coming it’s way soon.  Also if you think you have a site Dope Awards worthy then why not get it posted.

Bookmark and Share

3 Contact forms, 3 Sizes AS2/AS3

July 8th, 2009

With the Simple flash AS3 contact form recently seeing over 5000 downloads I’ve decided to add a new one.

Bit better looking than the last with help file and all code commented :)

Get Adobe Flash player

Included are:

  • contactForm.fla (Flash 8 )/contactForm.fla (Flash 9 )
  • caurina tweener classes AS2/caurina tweener classes AS3
  • contact.php
  • kharon4a_mini font
  • index.html
  • contactForm.swf
  • AC_RunActiveContent.js

Features:

  • Three different sized forms
  • All fields validation
  • Email validation
  • No reference to root. Simply drag the required form on to your project from the library
  • Courtesy thank you email sent to the form submitter, can be turned off
  • IP address capture and display link to ip look up tools in sent email
  • Nicely formatted html email. Can be set to send html or none html formatted email
  • Only 3 variables to be set in the php script and your good to go

Font(s) used:

  • kharon4a_mini

http://www.orgdot.com/aliasfonts/

How to modify the file:

Instruction 1: Open the contact.php script and go to line 11 and add your email, sitename and your name
php vars to change in php script

Once that is done you can upload the script to your server

Instruction 2: There are 3 other options found between line 16-21. $sendHtml, $sendCourtesy and $fColour

Additional php vars option that can be changed

These option can be left as they are.

Instruction 3: Simply drag ‘n’ drop the required form mc from the library onto your project. Also make sure to copy over the caurina tweener classes to your project folder and the contact.php script.

Movieclips that should be dragged onto your projects

The php script has been tested on a linux based server and windows dedicated server with php support.

Download 3 Contact forms, 3 Sizes AS2/AS3 Version v0.1

Bookmark and Share

Avoid manic button press

July 1st, 2009

I had to create a function where by I could avoid the button being pressed to quickly as some clicks where not being registered.


Some people will click a button as quickly as they can to see if they can break it lol.

  1. var reEnable:Number;
  2. button_mc.onPress = function() {
  3.  trace("the button was pressed");
  4.  disableButton(this);
  5. };
  6. function disableButton(b:MovieClip):Void {
  7.  b.enabled = false;
  8.  clearInterval(reEnable);
  9.  reEnable = setInterval(this, "reEnableButton", 1000, b);
  10. }
  11. function reEnableButton(b:MovieClip):Void {
  12.  b.enabled = true;
  13.  clearInterval(reEnable);
  14. }
Download Disable button press Version 1
Bookmark and Share

Google flash maps api guestbook

June 18th, 2009

When I get the time I am trying to learn what I can of AS3. Over the past couple of months I’ve been messing around with the google flash maps api.

Initially I was a bit overwhelmed with it but I have stuck with it and built a simple guestbook system that use’s mysql+php on the back end.

Features include:

  • Custom controls
  • Custom icons
  • Custom markers
  • Custom infoWindow
  • Email notification of someone signing the guestbook
  • Bad word filter
  • http check on submitted url’s
  • Custom right click menu
  • Fullscreen toggle

Newly added features :22/05/09

  • Quick zoom //  Zoom in on point
  • Map Settings panel
  • Enable/Disable mouseWheel scroll
  • Enabled/Disable map mouse click zoom
  • Hide/Show map types panel
  • Hide/Show map zoom panel

And to tie it off I have also added a simple admin feature that allows use to edit/delete submissions to the guestbook.
You can login to the admin system by pressing CTRL+SHIFT this will bring up the login window. username:admin, password:admin

I just have a couple of things I want to get done before I move onto my next map experiment. Please feel free to let me know your comments.

View/sign the simple guestbook system

Bookmark and Share