Posts tagged actionscript 3.0
Actionscript 3.0 snap to grid
2Every actionscripter will come to a point in his/her life where the boss calls for a drag and drop application. If you’re really lucky he/she will even ask for the ability to let items snap to a grid.
The Example
Just start dragging the red thing and you will see that it snaps to the grid from the moment you enter it. If you let go of the red thing outside of the grid it will return to his base.
The code to snap
snapClip_mc.x = mouseX - mouseX%size; snapClip_mc.y = mouseY - mouseY%size;
Only two lines of code! Just let the clip that you want to ‘snap’ position itself on the position of the mouse (mouseX, mouseY) minus the position of the mouse (mouseX, mouseY) modulo the gridsize (the size of one squareside of the grid).
So, if the side of my square in my grid was 50, the size parameter would be 50. If it was 100, my size parameter would be 100.
What is a modulo?
I am glad you asked! The modulo, according to wikipedia, is: In computing, given two numbers (either integer or real), a and n, a modulo n is the remainder after numerical division of a by n, under certain constraints.
The aftermath
Just think of the possibilities! Checkers, monopoly, chess and many more are just a snap (no pun intended) away!
And maybe even scrabble, too!
Murten does an air app!
0It took a little longer than expected but here I am again sending messages to the interweb!
A few weeks ago I made an application that streams a couple of webcams totally live with the help of red 5.
“Well… that’s nice, little boy” I hear you guys and girls think, if it wasn’t for the totally awesome fact that some great people actually liked it and decided to feature it in their design book! This does not only mean that my application works but also that it looks nice!
I truly believe you guys and girls are as anxious as I am so I was so generous to provide you all with a screenshot.

Until then: keep watching the stars! (haha.. *ahum*)
Actionscript 3.0 mailto
0This may be an easy one for all you brainiacs out there but many people have asked me how to do the “mailto” stuff in actionscript 3.0
In actionscript 2.0 we would do:
getURL("mailto:mail@hotmail.com", "_blank");
And in actionscript 3.0 it’s almost as simple:
navigateToURL(new URLRequest("mailto:mail@hotmail.com"), "_self");
Don’t forget to import navigateToURL and URLRequest though!
import flash.net.URLRequest; import flash.net.navigateToURL;
deeplinking with swfaddress
1Alot of people complain about flash not being able to deep-link. (directly go to a certain section in a flash website). Well swfAddress is a piece of code that solves this issue and on top of that makes the browser “back” button available to use in a flash website.
Recently my main man Jannes “the karate kid with the golden smile” Van de Maele did a deeplinking test with swfaddress 2.1 (the latest released version).
It is safe to say he did a good job and saved loads of us freeloaders alot of possible trouble. You will see it’s pretty straight forward once you check out the example, but to help you guys out I have some code snippets.
Add a listener to get feedback
SWFAddress.addEventListener(SWFAddressEvent.CHANGE, SWFADhandler);
Change the title of the document
SWFAddress.setTitle("set the title");
Set your page name
SWFAddress.setValue("page1");
Get your page name (do this in the change handler perhaps)
var address = SWFAddress.getValue();
Actionscript 3.0 and Singletons
0Yesterday my friend Lord Singleton had to come over and we talked about a couple of variations of his dance.
The problem with Singletons is that they require a private constructor and as 3.0 doesn’t support that. So obviously you need a workaround. Here’s two that you could use.
