Friday, July 1, 2011

SHIFT+ENTER adding a new line - chat textfield

Looking all over the internet for a simple adding a new line when pressing SHIFT+ENTER... not to be found.

So, for the ones who also looked very long, here is an example.
This sample also disables the ENTER key. Only when you hit SHIFT+ENTER it adds a new line to the textfield

public class TextfieldSample extends Sprite
private var textfield:TextField;

public function TextfieldSample()
//Creating the textfield an adding it on stage.
textfield = new TextField();

//event to disable the ENTER key
textfield.addEventListener(TextEvent.TEXT_INPUT, handleTextEvent);
//event to enable SHIFT+ENTER key
textfield.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);

//Make it an input textfield
textfield.type = TextFieldType.INPUT;

//Just use border to show it easy on stage.
textfield.border = true;
//You need multiline for adding new lines.
textfield.multiline = true;


private function handleTextEvent(event:TextEvent):void
if (event.text.charCodeAt() == 10)
//char code 10 == ENTER key

private function handleKeyDown(event:KeyboardEvent):void
if(event.keyCode == Keyboard.ENTER)
//You need to give something else the focus, otherwise the textfield is blocked
//and adding the new line will not work.
stage.focus = stage;
//Don't use appendtext for adding a new line, this function does not puts the new line in the correct position.
textfield.replaceText(textfield.selectionBeginIndex, textfield.selectionBeginIndex, "\n");
//Give the textfield the focus again
stage.focus = textfield;

If you have any improvement for this code, just let me know...

Tuesday, May 3, 2011

AS3 - Children adding reverse

Today I learned an extra feature of adding children into a DisplayObject in reverse.
Normally I would make two loops. First one is adding the children, the second is placing the children in reverse.
But... it can be done so much easier:

for(var i:int = 0; i < numChildren; i++)



The second parameter sets the child on the first place.

For many known, not for me.. maybe not for you either....

Thursday, July 23, 2009

getNextHighestDepth in as3

In as2 you were able to put a movieclip on top of all the other containing movieclips. I'm working with as3 now and was searching for this same option.

You can do it with one line of code:


//container is the parent of the movieclip


//container is the parent of the movieclip
container.setChildIndex(movieclip, (container.numChildren - 1));

Monday, June 15, 2009

[Project] Van zolder tot Loft < - > Papervision

Amercom developed an interactive test to find out what you can do with your attic. Through a serie of questions you will be advised what to do with your attic. Behind the test are some very interesting articles about defining and designing your attic. Our challenge was to create an interactive, creative and simple way to ask the questions.

So we used Papervision 3d to show different questions on a floor. You 'fly' above to the next question each time you have choosen your answer.
My goal was to find out how to use papervision in an efficient way so every ones framerate was above 20. Another challenge for me was to get the interactivity and Papervision work together. For me it was hard to get the mouse clicked or drag very smooth. But it worked out very well.

You can see the test here:

For any questions about papervision or interactivity in this project, please comment
Graphic credits goes to Benjamin Gouverneur

SoundManager in as3

On the internet I found a very interesting class. I used it in a project I'm working on right now. It is a singleton class to load library or external sounds. So with some very simple lines of code you can implement and use the sounds.

you can download the class here:

In your flash file you can set a linkage to the sound in your library:

To use the soundmanager simply use these lines:

//load the sound from library
SoundManager.getInstance().addLibrarySound(nl.Amercom.Sounds.MenuItem, "MenuItem");

//play the sound on a rollover or somewhere else

Sunday, April 5, 2009

Unable to resolve for transcoding with embed image

Ok, at home I was making a new as3 project with flashdevelop.
Everything was working great, untill I wanted to use the [embed] code.

At work there's no problem with it, but here at home it just didn't work. And I was sure that I dit the same thing... here is what I did,

protected var myImage:Class;

The compiler gave me this error: Error: Unable to transcode ../images/425400.png.
So, I thought to put the image in the /bin directory. not working either.

protected var myImage:Class;

after some searching on the internet, days of waiting and thinking... the solution was way to simple:

protected var myImage:Class;

put a '/' before you're path and it works..

Wednesday, January 14, 2009

[project] Interhome holiday suitcase in flash

After a lot of work, we created a new website for Interhome. It becomes a filled suitcase which checks your holiday character in a motion environment.
The style is designed by Benjamin Gouverneur and everything in flash is done by me.. Except the animations inside the suitcase. Martin Strieder is the creative animator. So my job was to put all the pieces together. A very creative, long and exciting project. One of the first big projects for me.

special credits go to Benjamin, Wouter, Jeroen and Martin!!