0
votes

I want to know how(and what scripts) to take words from a text input box and cause it to display and image Ex: if the text box said "smiley face" in it, then the image "smiley_face.jpg" would display on a certain movieclip and can be dragged around the stage and when a new image is loaded, it doesn't replace the previous image on the movie clip.

2

2 Answers

0
votes

You need to listen for the textInput event and you need to constantly search for "smile" using something like the search() function(u can use strings or regular expressions).

It returns -1 if the string you're searching for wasn't found, otherwise it returns the first index where the searched string was found.

Here's a really basic example:

var ti:TextField = new TextField();
ti.type = TextFieldType.INPUT;
ti.border = true;
addChild(ti);
ti.addEventListener(TextEvent.TEXT_INPUT, onInput);

function onInput(event:TextEvent):void {
    if(ti.text.search('smile')!=-1) trace('display smiley image');
}

You did mention smileys, so depending on your level of comfort with actionscript 3, it might be also worth having a look at Thibault Imbert's SmileyRenderer. Careful it uses the new FTE so you need to use Flash Player 10, etc.

0
votes

yeah. In ActionScript you need to add a listener event to the text field. then you can do something like this. My action script is not so good so I will just stick with logic.

 if listener.text == "smile"
    smile.jpg
 else if listener.text == "frown"
    frown.jpg
 else
    default.jpg
 end

You should check out lynda.com for their basic AS screencasts