A Flash Developer Resource Site

Page 3 of 3 FirstFirst 123
Results 41 to 58 of 58

Thread: [F8] Writing an array in a text file

  1. #41
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    */ does not belong in the text file (test.txt) see note below
    test4.txt will not work, as only the last values of x,x2,x3,y,y2,y3 are compiled
    PHP Code:
    lv = new LoadVars();
    lv.load("test4.txt");

    lv.onLoad = function(){
    trace(unescape(this));
    };

    /* note this is a block comment delimiter operator, usage -
    /* comment
    comment */
    /*
    the lv.onLoad compiles as - 
    lv = [object #1, class 'LoadVars'] {
        onLoad:[function 'onLoad'],
        NumItems:"3",
        x:"0,y=0",
        x2:"-13,y2=58",
        x3:"143,y3=-7"
      }
    */ 
    this is the error msg
    if you mean the output below, this is not an error, it is the result of trace();

    arr[0][0] --P 5
    arr[0][1][0][0] -- 0
    arr[0][1][0][1] -- 0 0
    arr[0][1][0][2] -- 123 123

  2. #42
    Member
    Join Date
    Aug 2007
    Posts
    87

    What am I doing wrong

    Everytime I test this out, I am getting know where. Is there something else that I am suppose to be doing to get this to draw on the stage? You have been a great help so far. I feel incompetent but I am actually real good in flash but my script skills kind of suck.

  3. #43
    Member
    Join Date
    Aug 2007
    Posts
    87

    Text file

    With that file test4.txt, what if I just name all the coordinates in consecative order like x,y x2,y2 x3,y3 x4,y4 x5,y5 etc. Would that work if I did it that way? I am also including another version of the text file, if you could give me your input that would be appreciated. All I did was move the commas so that each x,y coordinate is within a comma.
    Attached Files Attached Files
    Last edited by dm2757; 08-27-2007 at 03:16 PM.

  4. #44
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    913
    Yeah, you'll have quite a bit of rewriting to do...And sorry for the long wait...while I get back from vacation (I'll need to refresah my memory on XML), I know exactly how to use the loadVariables method in this case. Basically, just make every value a variable, BUT, if you have an array, that whole array can be under one variable EX:

    &arrayone = value1,value2,value3

    Then, in flash:

    loadVariables("square.txt")

    arraything = arrayone.split(',')

    Basically, what that just did, is load the arrayone variable, then, using the split function (which is very useful when using loadVariables), we split the arrayone var wherever there's a comma(,), and then Flash puts the seperated pieces into an array automatically called arraything(which is why you write: arraything = ).

    Now, I didn't really understand the text file, but you have background colour there too? What you'll need in flash is then a background MC. In Flash, type in Color in actionscript, highlight it, and press F1, since I forget the color object details, but it's easy to learn. All I know is that your gonna need all 6 values in the colour thing instead of 3.

    Now, to use the coordinate Array, you'll obviously either need 2 arrays, Xarray or Yarray, or, you can have one Array, with xvalue, yvalue, xvalue, yvalue and so on.

    Now, to interpret those variables, and draw a line...Here are some codes:

    TEXT FILE:

    &arrayY=5,10,15,20,25,35,20,50,20,15,0,0,0,10,5 ,
    &arrayX=5,10,5,10,20,10,15,40,5,10,15,30,50,5,5 ,

    FLASH:

    loadVariables('text.txt')

    arrayY = arrayY.split(',')
    arrayX = arrayX.split(',')

    createEmptyMovieClip('line',1)
    line.lineStyle(0x000000, 1)

    for (i=0;i<arrayY.length,i++) {
    line.lineTo(arrayX[i],arrayY[i])
    }

    That SHOULD do it, anymore problems just tell...
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  5. #45
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    this is the simplest method i could find for you.

    text file defines number of shapes - &shapes=3&
    each pair of co-ordinates on a separate line, be sure there are no
    spaces at the end of each line. (note 1st line format, don't deviate)
    each shape separated by 2 lines -
    Code:
    &shapes=3&0 0
    0 123
    123 123
    123 0
    0 0
    
    
    -13 59
    -14 74
    -18 88
    -24 102
    -33 114
    -44 125
    -56 134
    -70 140
    -84 144
    -99 146
    -114 144
    -129 140
    -143 134
    -155 125
    -166 115
    -175 102
    -181 88
    -185 74
    -186 59
    -185 44
    -184 29
    -175 15
    -166 3
    -155 -8
    -143 -16
    -129 -23
    -115 -27
    -100 -28
    -85 -27
    -70 -23
    -56 -17
    -44 -8
    -33 3
    -24 15
    -18 29
    -14 43
    -13 58
    
    
    143 -7
    204 116
    266 -7
    143 -7
    load into a LoadVars object, split to a multi-dim. arrays - _root["arr"+n]
    create an object (xPos & yPos) from the arrays and push to shape arrays
    use 3 buttons - btn0, btn1, btn2 to draw the shapes -
    PHP Code:
    lv = new LoadVars(); 
    lv.load("test4.txt"); 

    lv.onLoad = function(){ 

    str unescape(this);
    str str.split("&onLoad=[type Function]").join(""); 
    str str.split("\r\n").join("**"); 
    temp str.split("******");
    num lv.shapes*1

    for(var 
    n=0;n!=num;n++){ 
    _root["arr"+n] = [temp[n]];
    _root["shape"+n] = []; 
    len _root["arr"+n].length;
    for(var 
    nn=0;nn!=len;nn++) {
    _root["arr"+n][nn] = _root["arr"+n][nn].split("**");
    len2 _root["arr"+n][nn].length;
    for(var 
    nnn=0;nnn!=len2;nnn++) {
    _root["arr"+n][nn][nnn] = _root["arr"+n][nn][nnn].split(" ");
    obj = {};
    obj.xPos _root["arr"+n][nn][nnn][0];
    obj.yPos _root["arr"+n][nn][nnn][1];
    _root["shape"+n].push(obj);
    }
    }
    }
    // clean up
    for(var n=0;n!=num;n++){ delete _root["arr"+n]; }
    delete tempdelete strdelete lv;
    }; 

    btn0.onRelease = function(){ 
    // draw shape0
    _root.createEmptyMovieClip("mc0",0);
    mc0.lineStyle(50xFF00FF100);
    mc0.moveTo(shape0[0].xPosshape0[0].yPos);
    s0 shape0.length;
    for(var 
    s=1s!=s0s++){
    mc0.beginFill(0x0000FF30);
    mc0.lineTo(shape0[s].xPos,shape0[s].yPos );
    mc0.endFill();
    }
    };

    btn1.onRelease = function(){ 
    // draw shape1 : note draws offstage due to negative numbers
    _root.createEmptyMovieClip("mc1",1);
    mc1.lineStyle(50xFF00FF100);
    mc1.moveTo(shape1[0].xPosshape1[0].yPos);
    s1 shape1.length;
    for(var 
    s=1s!=s1s++){
    mc1.beginFill(0x0000FF30);
    mc1.lineTo(shape1[s].xPos,shape1[s].yPos );
    mc1.endFill();
    }
    };

    btn2.onRelease = function(){ 
    shape2.pop();
    // draw shape2
    _root.createEmptyMovieClip("mc2",2);
    mc2.lineStyle(50xFF00FF100);
    mc2.moveTo(shape2[0].xPosshape2[0].yPos);
    s2 shape2.length;
    for(var 
    s=1s!=s2s++){
    mc2.beginFill(0x0000FF30);
    mc2.lineTo(shape2[s].xPos,shape2[s].yPos );
    mc2.endFill();
    }
    }; 
    hth test files attached
    Last edited by a_modified_dog; 11-30-2007 at 10:43 AM.

  6. #46
    Member
    Join Date
    Aug 2007
    Posts
    87

    Check this out

    This is what it is suppose to create when it is finished. No buttons, just shapes. I have written 2 different txt files but I dont know which will be easier. You have seen them both already but I am not sure, I am having a long day. The file with the shapes, I hard coded it and entered all the coordinates manually, but I dont want to have to enter them manually. Does that make any sense at all?
    Attached Files Attached Files

  7. #47
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    no buttons in this one
    Last edited by a_modified_dog; 11-30-2007 at 10:43 AM.

  8. #48
    Member
    Join Date
    Aug 2007
    Posts
    87
    Thank you I will have to take a look at it tommorrow. My day is finally coming to an end.

  9. #49
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    ps .. to draw a circle, use simpler code -
    PHP Code:
    drawCircle = function(rxxyyplinefillop){
    lineStyle(1line);
    beginFillfillop);
    moveTo(xx+ryy);
    Math.tan(0);
    for (var 
    angle 1angle<=pangle += 1) {
    var 
    endx r*Math.cos(angle*Math.PI/180);
    var 
    endy r*Math.sin(angle*Math.PI/180);
    var 
    cx endx+r*a*Math.cos((angle)*Math.PI/180);
    var 
    cy endy+r*a*Math.sin((angle)*Math.PI/180);
    this.curveTo(cx+xxcy+yyendx+xxendy+yy);
    }
    };
    /*
    r: radius
    xx,yy: coordinates for the center of the circle
    p: angle
    line: line color
    fill: fill color
    op: filling opacity
    drawCircle(r, xx, yy, p, line, fill, op)
    */
    drawCircle(501501503600xff00000x00fff050); 
    hth

  10. #50
    Member
    Join Date
    Aug 2007
    Posts
    87

    Thanks

    Thanks for the help. What you have been helping me with is actually nothing. This is a small file. The next file is 350 pages of coordinates that creates a map. So I just have to try to figure out a more efficient way to rewrite the text file. I just started this job and they want to start doing things in flash so we are trying to figure out how to take the files that they already currently have and convert them to something that is, like I said more efficient and that can be read in flash.

  11. #51
    Member
    Join Date
    Aug 2007
    Posts
    87
    I finally was able to look at that shapes file. Why is it all over the place? When you tested it did it look normal? What I saw was strange. I could barely make out the shapes. The fill was covering all the shapes. Is it suppose to look that way?

  12. #52
    Member
    Join Date
    Aug 2007
    Posts
    87
    Are you having problems with the one that you had sent me freezing up Flash? Everytime I try to run it, it tell me to abort.

  13. #53
    Member
    Join Date
    Aug 2007
    Posts
    87

    New File

    Ok I have rewritten the txt file which I have included. I used commas to separate x,y and I used a bitwise"|" to separate each x,y pair. The ansperand "&" I used to separate the shapes. Now that I have that can I write an array and have Flash draw that?
    Attached Files Attached Files
    Last edited by dm2757; 08-28-2007 at 02:16 PM. Reason: added files

  14. #54
    Member
    Join Date
    Aug 2007
    Posts
    87

    Making headway

    I think I am making headway. I created a txt file that can be read into flash but the script must be off somewhere. Can you look at my script and my txt file and see where the problem is? I am getting a mesh of shapes. The shapes are suppose to be separated and right next to eachother. Thank You
    Attached Files Attached Files

  15. #55
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    alter the sequence in the drawShapes function -
    Code:
    	// draw shape0
    	_root.createEmptyMovieClip("mc0", 0);
    	mc0.lineStyle(1, 0x000000, 100);
    	mc0.moveTo(shape0[0].xPos, shape0[0].yPos);
    	s0 = shape0.length;
    	mc0.beginFill(0x00FF00, 100);
    	for (var s = 1; s != s0; s++) {
    	mc0.lineTo(shape0[s].xPos, shape0[s].yPos);
    	}
    	mc0.endFill();
    	mc0._x = 100;
    	mc0._y = 125;
    this is as far as I can go with you on this one
    good luck with your map

  16. #56
    Member
    Join Date
    Aug 2007
    Posts
    87
    Thank you, you have been a huge help

  17. #57
    Member
    Join Date
    Aug 2007
    Posts
    87

    Major Headache!

    My brain is starting to hurt and I have no idea where my problem is. The shapes are still in a mesh form. When I pull up the output on the previewed product, there is a stray coordinate that should be on the bottom shape. The stray coordinate is 0,0 and it is making its own object. I dont know what to do. Can you help again please?
    Attached Files Attached Files

  18. #58
    Member
    Join Date
    Aug 2007
    Posts
    87

    Can anyone help?

    I am feeling like I just hit a brick wall. I am part of the way their in what I am trying to do. I have a txt file that I am reading into flash 8 and I have the script written that reads in the file and draws it but it is off somewhere. it is suppose to draw 3 consective shapes in a row a circle, square and a triangle and all shapes are green. Can someone help me figure out what is going wrong? I am desperate for help at this point.
    Attached Files Attached Files

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