Posts tagged actionscript 3.0

Actionscript 3.0 snap to grid

2

Every 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!

0

It 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.

spaceApp

Until then: keep watching the stars! (haha.. *ahum*)

Actionscript 3.0 mailto

0

This 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;

Actionscript 3.0 Key Listener after button-click

0

Today I found out that a Actionscript 3.0 Key Listener doesn’t work after a button-click until you click somewhere on the stage. Ofcourse I made it a quest to find out how I could easily fix this and behold!

The problem

private function someFunction():void {
	start_btn.addEventListener(MouseEvent.CLICK, clickHandler);
	start_btn.buttonMode = true;	
}
 
private function clickHandler(e:Event):void {
	removeChild(start_btn);
	stage.addEventListener(KeyboardEvent.KEY_DOWN, downHandler);
}
 
private function downHandler(e:Event):void {
	trace("heej");
}

It will not do the trace until you click the stage. So I went on a searching spree and together with my good friend Frederik “the wonderkid” Humblet found out that “stage.focus = null;” fixes it. Well, he found out, but I steal the credits by posting it for you all!


The solution

private function someFunction():void {
	start_btn.addEventListener(MouseEvent.CLICK, clickHandler);
	start_btn.buttonMode = true;	
}
 
private function clickHandler(e:Event):void {
	removeChild(start_btn);
	stage.focus = null;
	stage.addEventListener(KeyboardEvent.KEY_DOWN, downHandler);
}
 
private function downHandler(e:Event):void {
	trace("heej");
}

Until next time my dear readers!

Embedding fonts in actionscript 3.0

0

Embedding a font is what you do if you don’t want the user viewing his own version of the font or – even worse – a totally different font.

Embedding a font is quite useful for a couple of reasons, namely:

- You can rotate embedded fonts.
- The text looks alot more smooth.
- Your text supports transparency.

If you’re looking for a universal way to easily embed your fonts in actionscript 3.0 this may be the class you want!

Originally written by my main man Jannes this class basically sets all the stuff you need to embed a font and therefore is a must have for every serious developer.

(more…)

deeplinking with swfaddress

1

Alot 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

0

Yesterday 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.

(more…)

Go to Top