Question about lineTo . . . from a text file?

I have a question about lineTo.

Let’s say I wanted to dynamically draw a cityscape - just a bunch of straight lines and right angles. But there are lots of x,y coordinates to make the whole thing. Would it possible to put all those coordinates in a text file and then call that from Flash? As in, lineTo(use line 1 of text file, then use line 2, then use line 3) etc.

Is this possible? And if so, what sort of AS is used? And does the text file have to be in a certain formate? (like x,y one per line or on one line separated by parentheses, or . . . ?).

Thanks for any help!:}


var lineLoad = new LoadVars();
lineLoad.load("example.txt");
lineLoad.onLoad = function(){
	_root.createEmptyMovieClip("holderClip",100);
	coords = this.coords;
	coords = coords.split("|");
	for(var i = 0;i<coords.length;i++){
		coords* = coords*.split(",");
	}
	_root.holderClip.lineStyle(1,0x000000, 100);
	for(var i = 0;i<coords.length;i++){
		_root.holderClip.lineTo(coords*[0], coords*[1]);
	}
}

and the values of the text file:
&coords=20,30|40,50|10,12|430,21

Hey thanks! I’ll give it a shot.

:smiley:

Didn’t work . . . :h:

I’m not sure I’m accessing the text file. Here is what I have:


var lineLoad = new LoadVars();
lineLoad.load("numbers.txt");
lineLoad.onLoad = function(){
        _root.createEmptyMovieClip("holderClip",1);
        coords = this.coords;
        coords = coords.split("|");
        for(var i = 0;i<coords.length;i++){
                coords* = coords*.split(",");
        }
        _root.holderClip.lineStyle(2,0x000000, 100);
        for(var i = 0;i<coords.length;i++){
                _root.holderClip.lineTo(coords*[0], coords*[1]);
        }
}

and when I test the movie it’s just blank.

Any suggestions?

Here are my files:

Hey NJS - I couldn’t open your fla :frowning: I got an “unexpected file format”.

Also, is there any way to use the text file without using the “|”? I have a LOT of coords.

And finally, do the numbers have to be rounded? Can I use tenths?

Thanks for your help!

well, the way it all works is that it uses a logical separator(in this case |) to separate the coordinates, so it would be quite difficult to think of a way without using some separator. You can use a different one though, just replace the | with the other character :). I think you should be able to use tenths.

And you’re welcome - I’d done something very similar to this before so it was only a case of modifying it slightly.

Hey that works great! Thanks! Sorry I forgot to mention I was using MX :blush:

Question - how can I get it to draw more slowly? Even if I change the frame rate to 0.1 it sort of just appears. I would like the shape to draw itself as the viewer watches. Is it possible to set a drawing rate in AS?

Thanks again!:s: