A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Divide/Multiply text fields populated from .txt file

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    3

    Divide/Multiply text fields populated from .txt file

    Good Morning/Afternoon/Evening

    My friends and I play a table top game and I am attempting to make a character sheet template in Flash 8 AS2 to reduce down time. I have created a character sheet template using Flash that imports all the base stats from a .txt file. I have gotten all my information to populate to the text fields desired like strength, dexterity, intelligence and so forth. What I would like is for Flash to take the value of say strength and populate the value of what strength represents (which would be a physical damage modifier) in a text field next/near it but not necessarily concatenation. To get the values of your stats is very simple math. Strength divided by 2 equals damage modifier, easy math. Constitution multiplied by 3 equals max hit points, again easy math. While this is easy math, it does take time out of the game to manage these values on paper and if I can create my vision here I can enhance the value of our game time. It is important that the stats are drawn from a text file because none of my fellow players know Flash or have Flash.

    In the end I will need it to do more than just this but to begin I would like to start by understand how to take the value of strength's text field and divide it by two then put it in another text field. I would also like to be able to be able to take the value of strength and divide it by the value of dexterity and populate that to another field. I am confident that once I have this information I could crash course threw all the rest of it.

    I've been searching on and off for 3 days now but I think I know so little action script that I don't even know how to find the information I am looking for because all I find is information on how to load a text file and I know that already. I've found information on how to do math in flash, played with that and made it work but I was not able to use it from my .txt dynamically loaded text fields. It just populated text fields itself, put the numbers in it from the script and then populated another text box for the sum. Unfortunately my Flash experience is little more than making personal information web sites or stuff like greeting cards and call flow scripts but I thought I knew enough to make this happen or learn along the way.

    In short I am looking to:

    get value of strength text field and divide by two then populate sum to damage text field
    and
    get value of strength text field divide it by the value of dexterity text field then populate the sum to str/dex text field.

    A source file which should make it obvious what I accomplished thus far and looking to do from there.
    character_sheet.zip
    character_sheet.zip only includes the char.fla and the char.txt


    I appreciate any/all attention you have to offer me

  2. #2
    Junior Member
    Join Date
    Sep 2012
    Posts
    3
    I have managed to find the answer =)

    Code:
    var lv:LoadVars = new LoadVars();
    lv.onLoad = function(success) {
        if (success) {
            c_name=this.c_name;
            job=this.job;
            race=this.race;
            str=this.str;
            pdmg=str/2;
            dex=this.dex;
            phit=dex/2;
            agi=this.agi;
            eva=agi/2;
            con=this.con;
            hp=con*3;
            spi=this.spi;
            mp=spi*3;
            chrm=this.chrm;
            mhit=chrm/2;
            smart=this.smart;
            mdmg=smart/2;
            wis=this.wis;
            mres=wis/2;
        }
    };
    lv.load("char.txt");

  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    do as Crux says, also change your char.txt to
    Code:
    &c_name=INO&
    &job=NINJA&
    &race=HUMAN&
    &str=8&
    &dex=8&
    &agi=8&
    &con=8&
    &spi=8&
    &smart=8&
    &chrm=8&
    &wis=8&
    you will need to change some of the text field var names to the corresponding names in the file too.
    and embed the text.
    they needed to be changed as they clash with built in function names and variables.

    you are Crux, silly me. lol. txt file anyway

  4. #4
    Junior Member
    Join Date
    Sep 2012
    Posts
    3
    they needed to be changed as they clash with built in function names and variables.
    Yah I found that out heh heh. Flash was all like "Bitznotch the word "CLASS" r' belongs to us! NO soup for you!" So I changed CLASS, CHR and INT and Flash is ok with it now.

    Currently suffering threw getting it to do all the maths I desire with my beginners knowledge. I had a hard time for a short while with the add symbol. It was trying to tell me 8+2=82 as if + is concatenate but I think I got that figured out. I haven't gotten an opportunity to work it out yet but I will.

    Also I want to change to instanceName.text=valueOfTheText; cause I understand var:Name may cause more problems as I get more involved with it. This is all new to me. I'm just a GUI button pusher. If I can't hit the + symbol on script assist, navigate the menu to my command and fill in my names and locations then I am outside of my comfort zone. If it wasn't for Macromedia's super sexy GUIs I'd of never gotten into web development. I have the creative foresight to design gorgeous informational web sites but they're only visually appealing and not impressive via code at all.

    So all being said I have quite a bit to keep me busy for quite some time. As a newb it'll be a lot of adding a text field point to it and publish, then change script if needs be and publish, then repeat till all fields populate the info I desire. There's quite a bit of trial and error time involved to create my entire vision of this char_sheet and that is cool cause since I quit playing MMORPGs I have quite a bit of spare time to fill and I can't think of a better way to fill it than expanding my web site design skills.

    I certainly do appreciate your attention =)

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    to help you with the + of variables you can always do this:

    Code:
    agi = this.agi;
    eva = parseInt(agi) + 2;

  6. #6
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Better still for your adding, use:

    Code:
    var lv:LoadVars = new LoadVars();
    lv.onLoad = function(success)
    {
    	if (success)
    	{
    		c_name = this.c_name;// no need to parse names/words
    		job = this.job;
    		race = this.race;
    
    		str = parseInt(this.str);
    		pdmg = str / 2;
    		dex = parseInt(this.dex);
    		phit = dex / 2;
    		agi = parseInt(this.agi);
    		eva = agi / 2;
    		con = parseInt(this.con);
    		hp = con * 3;
    		spi = parseInt(this.spi);
    		mp = spi * 3;
    		chrm = parseInt(this.chrm);
    		mhit = chrm / 2;
    		smart = parseInt(this.smart);
    		mdmg = smart / 2;
    		wis = parseInt(this.wis);
    		mres = wis / 2;
    		all = str + dex + agi + con + spi + chrm + smart + wis + 2;
    	}
    };
    lv.load("char.txt");

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center