How to call a jpg image for every character that is typed

  • fmapps
  • Born
  • Born
  • fmapps
  • Posts: 4

Post 3+ Months Ago

Hey Folks. Just starting into using flash and reading up a bit about it. Could someone point me in the right direction on what I need to do for this :-> I want a user to type into an Input text box, example there city. I want to then call a jpg for every character type. So if the type New York, I want to call and show a jpg with the city of new york for example?

Thanks Folks
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

action script 2 or action script 3?
  • fmapps
  • Born
  • Born
  • fmapps
  • Posts: 4

Post 3+ Months Ago

ActionScript 3 hopefully.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

then in first step check out for: input text addEventListener KeyboardEvent.KEY_DOWN
second step: as3 load image
I'll provide you some sample code with the input text part, the image part you do the research for it.
Assuming you have an input text on the stage, with the instance name inputText :
Code: [ Select ]
inputText.addEventListener(KeyboardEvent.KEY_DOWN,inputText_onKeyDown);
function onKeyDown(evt:KeyboardEvent){

  // if the key is ENTER
  if(evt.charCode == 13)
  {
    // your code here
    ProcessWord(inputText.text);
  }
}

function ProcessWord(word:String)
{
    word = word.toLowerCase();
    switch (word)
    {
        case "new york": LoadSomeImage("images/newyork.jpg"); break;
        case "london": LoadSomeImage("images/london.jpg"); break;
    }
}

function LoadSomeImage(imagePath:String)
{
  trace("loading image:" + imagePath);
  // here you do the image load
}
  1. inputText.addEventListener(KeyboardEvent.KEY_DOWN,inputText_onKeyDown);
  2. function onKeyDown(evt:KeyboardEvent){
  3.   // if the key is ENTER
  4.   if(evt.charCode == 13)
  5.   {
  6.     // your code here
  7.     ProcessWord(inputText.text);
  8.   }
  9. }
  10. function ProcessWord(word:String)
  11. {
  12.     word = word.toLowerCase();
  13.     switch (word)
  14.     {
  15.         case "new york": LoadSomeImage("images/newyork.jpg"); break;
  16.         case "london": LoadSomeImage("images/london.jpg"); break;
  17.     }
  18. }
  19. function LoadSomeImage(imagePath:String)
  20. {
  21.   trace("loading image:" + imagePath);
  22.   // here you do the image load
  23. }
  • fmapps
  • Born
  • Born
  • fmapps
  • Posts: 4

Post 3+ Months Ago

Thanks for the Point in the right direction dude, Appreciate it. Gonna give it a go tonight and hopefully get somewhere with it. Peace
  • fmapps
  • Born
  • Born
  • fmapps
  • Posts: 4

Post 3+ Months Ago

Hi there.
I got somewhere with this code. Problem is its too basic. Ie. If i Type "a" shows a.png at x=100 y=100 etc. Any idea how I can use variables to say. "First characther typed, show thatchar.png" I need a variable to catch the 1st char typed and show that char image file, does that make sense? Thanks.

//draw input box

var inputField:TextField = new TextField();

addChild(inputField);

inputField.border = true;
inputField.width = 200;
inputField.height = 50;
inputField.x = 75;
inputField.y = 50;
inputField.type = "input";
stage.focus = inputField;
inputField.restrict = "abcdefghijklmnopqrstuvwxyz";

//var firstchar:String = inputField.charAt(0);
//Set up Events
inputField.addEventListener(KeyboardEvent.KEY_DOWN,reportKeyDown);

function reportKeyDown(event:KeyboardEvent):void
{
trace("Key Pressed: " + String.fromCharCode(event.charCode) + " (key code: " + event.keyCode + " character code: " + event.charCode + ")");
if (event.keyCode == 65) LoadSomeImagea();
if (event.keyCode == 66) LoadSomeImageb();
}

function LoadSomeImagea()
{
var libImage:A = new A(0,0);
var holder:Bitmap = new Bitmap(libImage);
holder.x=100;
holder.y=100;
addChild(holder)
}

function LoadSomeImageb()
{
var libImage:B = new B(0,0);
var holder:Bitmap = new Bitmap(libImage);
holder.x=150;
holder.y=100;
addChild(holder)
}

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 4 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.