Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating line drawing from keypresses

Status
Not open for further replies.

HellsWoo

Technical User
Nov 6, 2002
9
GB

I want to create a line drawing based on key presses. Each key press will relate to a predefined xy co-ordinate on screen and when the next key is pressed a line will be drawn between the two and so on for the next keypress.

Having placed a node for each key on the screen I have compiled a list of all of the x co-ordinates (there are 21 values) and a list of all they co-ordinates (there are 3 values). For these I have created two arrays, one lX and one for Y, so that I can create values for each letter

Q [0] [0]

x = 65.8 (1st number in Array X)
y = 65.8. (1st number in Array Y)

Array X [65.8, 83.8, 101.8, 119.8, 137.8, 155.8, 173.8, 191.8, 209.8, 227.8, 245.8, 263.8, 281.8, 299.8, 317.8, 335.8, 353.8, 371.8, 389.8, 407.8, 425.8]

Array Y [65.8, 101.8, 137.8]

Basically I am unsure of how to relate the x and y values of the letters to the keypress. I.e.

Keypress 1 = B
Keypress 2 = A
Keypress 3 = D
Keypress 2 = G
Keypress 2 = E
Keypress 2 = R

Etc…

I find coding very difficult, so if anyone would be able to explain this it would be greatly appreciated.

Many Thanks

Helen
 
you need an addlistner for the keys then its a lineto statement to draw the line.

for the keys

Key.addListener(Key);
Key.onKeyDown = function(){
var dwn = String.fromCharCode(this.getAscii());
if (dwn.length) this.broadcastMessage("onKey"+dwn+"Down");
}

Key.addListener(this);
this.onKeyADown = function(){
trace("a pressed");
}
this.onKeyBDown = function(){
trace("b pressed");
}

this["onKeyCDown"] = function(){
trace("c pressed");
}


there might be a simpler way to capture keypresses then run a function than this as you will need lots of the above statements but at least this ought to work. get you started anyway.
 
Thanks for that, the code works, and I have added a count for the nnumber of keys pressed. num_keypress

this.onKeyBDown = function() {
trace("b pressed");
num_keypress += 1;
trace(num_keypress);
};

I want to use num_keypressed for the following array bu am not sure how to ensure it uses the current number in the variable:

keypress = new Array();
num_keypress = 0;
keypress[0] = keypress0;
for (z=0; z<num_keypress; z++) {
duplicateMovieClip(this.keypress0, (&quot;keypress&quot;+z), z);
keypress[z] = eval(&quot;keypress&quot;+z);
keypress[z]._x = (z*10);
keypress[z]._y = (z*10);
}
Thanks

Helen



 
not sure what you are trying to do here or why.

can you give some more detail.
 
When I press a key I want to make a point based on the x and y coordinates I described in the first post. As i have very little knowledge of flash I have been attemptign to use arrays, however am not entirely sure how to do so.

The the function will need to create a point based on the following bits of info.

When a key is pressed

a: you need to know how many key presses there have been previously.
b: which key was pressed i.e letter A, B etc
c: The corresponding x and y coordinates (the info is in the arrays in the 1st post)

This point then needs to be connected to both the previous point and next points.

Hope this provides more information

Thanks

Helen
 
yes arrays are the way to go

no code at the moment im a bit pushed for time but one way to go is

1.have the coordinates associated with the key in the function.
2. on key press add them to the array (look up array push)
3. when the user is finished
moveto (firstx,firsty)
linto(nextx,nexty)

and so on stepping through the array to have the shape drawn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top