Ask a Question related to Macromedia Flash, Design and Development.
-
GHM #1
arrow keys datagrid
Hi All,
Bought the Flash MX datagrid component from Macromedia. Standard it
does not handle the arrowkeys but they made an example on how to do it
using grid.setSelectedCell (code included on end of message).
Unfortunately setSelectedCel has the nasty habit of turning every cel
it targets into an editable cell even if it is not editable! The
function also sets the cel into edit mode adding typed characters to
the cell content instead of overwriting it.
Tab key navigation IS included in the datagrid and works just like it
should!
Any of you die-hard programmers know a solution ?
Here is my code:
All in frame1 with datagrid called "grid" on stage:
stop();
setData();
grid.setSelectable(false);
grid.setEditable(true);
// trap the arrow keys
this.tabListener = new Object();
Key.addListener(this.tabListener);
// key listener function
this.tabListener.onKeyDown = function() {
// get the coordinates
var myPos = grid.getSelectedCell();
// listen for the key and go in that direction
// each conditional calls the gridNav function
if (Key.isDown(Key.RIGHT)) {
gridNav(myPos.index, myPos.colName, "right");
} else if (Key.isDown(Key.LEFT)) { gridNav(myPos.index, myPos.colName,
"left");
} else if (Key.isDown(Key.UP)) { gridNav(myPos.index, myPos.colName, "up");
} else if (Key.isDown(Key.DOWN)) { gridNav(myPos.index, myPos.colName,
"down");
}
}
/*
this function checks the position of the current sellected
and stops if it has nowhere to go. You could also make it
wrap around to the next or previous row.
*/
function gridNav(index, col, dir) {
var colIndex = grid.getColumnIndex(col);
if (dir == "up") {
if (index == 0) {return;}
grid.setSelectedCell(index-1, col);
} else if (dir == "down") {
if (index == grid.getLength()-1) {return;}
grid.setSelectedCell(index+1, col)
} else if (dir == "right") {
if (colIndex == grid.getColumnCount()-1) {return;}
grid.setSelectedCell(index,
grid.getColumnAt(colIndex+1).getHeader())
} else if (dir == "left") {
if(colIndex == 0) {return;}
grid.setSelectedCell(index,
grid.getColumnAt(colIndex-1).getHeader())
}
trace("index: " + index);
trace("column: " + col);
trace("columnIndex: " + colIndex);
trace("direction: " + dir + "\n");
}
//-----------------
// get data locally
//-----------------
function setData()
{
var dP = new Array();
for (var i=0; i<10; i++) {
dP[i] = {first:"first", second:"second", nuts:"nuts",one:"one:"+i,
two:"two:"+i, three:"three:"+i, four:"four:"+i};
} grid.setDataProvider(dP);
}
----------------------------------------------------------------------------
----
GHM Guest
-
Arrow keys out of control - Wierd
Hi, I'm Illustrator deficient and just beginning the learning process of Illustrator CS utilizing the Total Training tapes. In lesson 3 there... -
Trying to get Enter or up/down arrow keys to move row to row in asp.net datagrid
Hi All, I've been trying to find a way to ape the action of the windows form enter key to an asp.net datagrid. That is, I would like to move to... -
arrow keys fail
Hi Folks, I published the completed example of the 'magic trick' director example, but on my PC using the arrow keys (or mouse click) fails to... -
using arrow keys 2 control a sprite???
i basically want to be able to control a sprite on the stage (in this case a car) by using the up, down, left and right keys! ive created 4... -
arrow keys in motif
I can't seem to get the arrow keys on the number keys to work in motif -- NetBSD 96key pc keyboard(with the ctrl key where god intended it) ...



Reply With Quote

