-
add or remove rows to a datagrid with AS2?
Hi there I've been trying to find a tutorial on how to add or remove rows to a datagrid and have only found this tutorial...
http://proquest.safaribooksonline.com/0131484753/ch50
which is great because it shows how to add columns to a datagrid, but how do you add and remove rows to the datagrid?
I'm trying to I'm trying to come up with a Character Generator for our Tabletop Wargame (see here http://www.twistedpancreas.com/test/...eneration.html), and rows to appear when you say click on a Weapon like Fist and then onto another weapon (Fist only works atm as a demo).
ie how could i format it so it was like a table (because at the moment the Fist stats are formatted with spacebar spaces), and how could i make it so that when you choose your 1st weapon it appears 1st in the table (say a Bow), and when you click your 2nd weapon it appears 2nd in the table (say a Sword), etc...
Thanks in advance.
-
ok well I got that working, ie
datagridName.addItem({Name:"Sword", Type:"Cuts"});
datagridName.dataProvider.removeItemAt(datagridNam e.selectedIndex);
when removing an item it should also minus the appropriate cost, but i'm not sure how to do that.
I've attached my attempt at it here http://www.twistedpancreas.com/test/datagridWeapons.fla (the flash preview of it can be seen here http://www.twistedpancreas.com/test/datagridWeapons.swf ), but it's just minusing a static value at the moment (ie 5)
Can anyone help?
Thanks in advance
-
Well someone else from another forum suggested this (which seemed to do the trick):
_global.gFinalCost = 0;
onEnterFrame = function(){
finalCost.text = gFinalCost;
}
var col:mx.controls.gridclasses.DataGridColumn;
var row:mx.controls.gridclasses.DataGridRow;
item = new Array();
item = [{Name:"",Type:"",Cost:""}];
test_grid.dataProvider = item;
test_grid.setSize(300,200);
test_grid.editable = false;
test_grid.removeColumnAt(2);
test_grid.dataProvider.removeItemAt(0);
test_grid.setStyle("alternatingRowColors",[0xFFFFCC,0xDBDBDB]);
//test_grid.getColumnAt(0).sortOnHeaderRelease = false;
//test_grid.getColumnAt(1).sortOnHeaderRelease = false;
test_grid.getColumnAt(0).sortable = false;
test_grid.getColumnAt(1).sortable = false;
test_grid.getColumnAt(0).width = 200;
test_grid.getColumnAt(1).textAlign = "right";
gun_btn.onRelease = function ()
{
test_grid.addItem({Name:"Gun", Type:"Shoots", Cost: 10});
gFinalCost += 10;
}
sword_btn.onRelease = function ()
{
test_grid.addItem({Name:"Sword", Type:"Cuts", Cost: 5});
gFinalCost += 5;
}
remove_btn.onRelease = function ()
{
if(test_grid.selectedIndex <> undefined) {
//trace(test_grid.dataProvider[test_grid.selectedIndex]["Cost"]);
gFinalCost -= Number(test_grid.dataProvider[test_grid.selectedIndex]["Cost"]);
test_grid.dataProvider.removeItemAt(test_grid.sele ctedIndex);
}
}
Which I've now incorporated into my Character Generator here: http://www.twistedpancreas.com/test/...ration004.html (which still needs some work, especially with text formatting, etc... do datagrids render fonts badly? I tried the font Impact and it came out un-antialiased and condensed).
Now some of the equipment has negative values to some of the input boxes (eg Chainmail is ARM +8, Ref -2, MV-1). If a user has typed a number into a input box (say Ref Lvl 5), can Flash then change that number later if a certain piece of equipment is chosen (as with Chainmail, thus Ref Lvl 5 would go to Ref Lvl 3)?
Because I tried
myRefTxt.text -= Number("2");
which seems to work, but when you add to the number
ie myRefTxt.text += Number("2");
it adds the 2 beside the input number
ie if you had inputted 3 into myRefTxt.text and then had a piece of equipment add 2, the input box says 32
Thanks once again for all this help.
-
ok looks like it should be
myRefTxt.text =Number(myRefTxt.text)+ Number("2");
Ok now hopefully here's one of my last problems, and I've uploaded it to here http://www.twistedpancreas.com/test/strongProblem.fla (http://www.twistedpancreas.com/test/strongProblem.swf).
You get to type in your Str value and then later on could choose a Trait like Strong (ie type in a value next to Strong then click Strong), problem is I have the Str input value in a onEnterFrame (so that you get instant feedback on how much the Str value costs), and so when the Strong trait value gets added to the Str value it appears for a millisecond then reverts to what was originally typed.
How do I get the Strong value to remain added to the Str value?
Thanks in advance.
Last edited by Pancreasboy; 11-27-2008 at 06:27 PM.
-
i would have thought the Strong button code inside "traits_mc" would have this:
gStrCost = Number(gStrCost) + (Number(myStrongTxt.text));
but that doesnt seem to work
-
any thoughts? or am I not making sense?
-
Ok someone on another forum suggested I put a trace in "traits_mc" at frame 21 AS and I got
gStrCost = 0 : myStrongTxt.text = 0
which seems fine and then they said to replace Number() with parseInt() but that didn't seem to work, see my updated file here: http://www.twistedpancreas.com/test/strongProblem1.fla
can anyone help?
-
well it looks like
strongStr = (Number(_root.myStrTxt.text)) + (Number(myStrongTxt.text))
_root.myStrTxt.text = strongStr;
does the trick to adjust the Str Lvl stat, see http://www.twistedpancreas.com/test/costProblem.swf
but it shouldn't adjust the Str Lvl cost beside it, anybody got any ideas on how I could avoid that? Updated file is here http://www.twistedpancreas.com/test/strongProblem.fla
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|