Variables from .txt file and timer/interval

..plus drawing shapes with actionScript

Page 1 of 1

5 Replies - 7973 Views - Last Post: 05 May 2006 - 02:41 AM

#1 Xenon  Icon User is offline

  • Connection failed
  • member icon

Reputation: 8
  • View blog
  • Posts: 1,595
  • Joined: 12-September 05

Variables from .txt file and timer/interval

Posted 03 May 2006 - 11:05 PM

-How do i read data from a text file ?

the text file uses "|" character as a break between different data fields.
so i have to read all te values, and pass them one by one to the respective text boxes, but NOT include the "|" character.
------------------------------
-is there a timer function in flash, as in VB ? i want an event to be triggered periodically, and can it be possible to change the period of the event during run time ?
-----------------------------
-ive tried searching for this, but i cant find anything useful which will show how to plot curves, parabolas, ellipses etc etc using actionscript.



thanks
Xenon

Is This A Good Question/Topic? 0
  • +

Replies To: Variables from .txt file and timer/interval

#2 theRemix  Icon User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 440
  • Joined: 19-October 05

Re: Variables from .txt file and timer/interval

Posted 04 May 2006 - 12:32 AM

the text file must be in this format:

variable1=value1&variable2=value2



& seperates variable/value pairs

in your case, you probably have 1 value

but you need to have a variable prepended to your text file.

for example

list=something1 | something2 | something3

then you can retrieve it using actionscript this way:

LoadVariables("myTextFile.txt", 0, GET);



then your variables are loaded, you can manipulate them by their variable name, which is loaded on level_0 or _root

so

trace(variable1);
or
trace(_root.variable1);

you can then make an array

var myArray = new Array();
myArray = _root.list.split('|');

or however you want to seperate your data by |

if you have special characters, you should use the ascii code equivalents, like %26
you can't have spaces in variable names or spaces before or after the =

this should work, but i haven't tested it. if you run into trouble, use the actionscript dictionary that comes with flash, (help), and search for LoadVariables or LoadVariablesNum , for a more concise definition and usage of these functions.

hth.
Was This Post Helpful? 0
  • +
  • -

#3 theRemix  Icon User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 440
  • Joined: 19-October 05

Re: Variables from .txt file and timer/interval

Posted 04 May 2006 - 12:41 AM

2nd question,

the timeline the easiest way to do things based on time, but is not accurate.

make a movie, by default the fps is 15 (if its not, make it 15 or 30), then calculate how many frames you'd need to have to do something periodically, and it loops automatically!

so if (at 15 fps) you wanted to display something for 1 second every 5 seconds, then expand your timeline (using f5) and create a keyframe on frame number 75 and then lengthen it to frame 90.
drop an image anywhere from frame 75 - 90
so it should look similar to this.
[   10    20    30    40   50   60   70   80   90]
[                                         ][=====]



if you wanted a code to run instead, drop the actionscript on frame 75, and have a total of 75 frames so
[   10    20    30    40   50   60   70 ]
[                                    ][a]



this is one way for quick and simple solutions. :)

hth
Was This Post Helpful? 0
  • +
  • -

#4 Xenon  Icon User is offline

  • Connection failed
  • member icon

Reputation: 8
  • View blog
  • Posts: 1,595
  • Joined: 12-September 05

Re: Variables from .txt file and timer/interval

Posted 04 May 2006 - 01:09 AM

thanks for the reply, the 1st reply is good enough for me atm, as im learning still.

but the second reply isnt what im trying to achieve, ill explain it better

- i have a form with controls, and the data needs to be updated periodically,
eg a Temperature / Time & Date counter. i cant figure out how will i use the TIMEline method in this case.

Xenon
Was This Post Helpful? 0
  • +
  • -

#5 pioSko  Icon User is offline

  • still.dreaming
  • member icon

Reputation: 23
  • View blog
  • Posts: 1,888
  • Joined: 06-June 03

Re: Variables from .txt file and timer/interval

Posted 04 May 2006 - 05:57 AM

there is a timer function in Flash. It executes a function in intervals set by you...
function echo(){
    trace("hello world");
}

var t = setInterval(echo, 1000);


In this example, the echo() function is executed every 1000 milliseconds (1 second)...

To stop the interval, use:
clearInterval(t);

... t being the name of the interval function.

-----

Curves and parabolas... and graphs in general... are done useing the moveTo(), lineTo() and curveTo() functions. The first one is basic. It moves the current position of your "pencil".. the point from which the next point will be drawn.
The second, lineTo(), is a basic straight line and all you do is give the function the coordinates of the next point.
Finally, curveTo() as you can probably guess is used to draw curves. He you have to pass on 2 pairs of coordinates.. x and y to draw to.. and a "curve handle", or point which sets the amount of curve.

So, in order to draw a square, all you'd need is the lineTo()... but circles, ellipses, parabolas and such, you'd use the curveTo(). In both cases, however, you draw the shape using a number of steps (ie. from this corner to the next.. then from that corner to the next..)

It may sound confusing at first, but it's worth while practicing this. It comes in handy when doing nice little effects sometimes.

Drawing a square:
this.createEmptyMovieClip("square", 2);
square.lineStyle(2, 0x990000, 100);
square.moveTo(100, 100);
square.lineTo(200, 100);
square.lineTo(200, 200);
square.lineTo(100, 200);
square.lineTo(100, 100);


Drawing a curve:
this.createEmptyMovieClip("curve", 2);
curve.lineStyle(2, 0x990000, 100);
curve.moveTo(100, 100);
curve.curveTo(150, 200, 200, 100);
curve.curveTo(350, 200, 400, 100);


You can draw shapes straight to _root, but I prefer to create an empty movie clip on the stage and have Flash draw "inside" it. This way you can manipulate your graph/drawing/shape using actionScript just like a normal movieClip.
Was This Post Helpful? 0
  • +
  • -

#6 Xenon  Icon User is offline

  • Connection failed
  • member icon

Reputation: 8
  • View blog
  • Posts: 1,595
  • Joined: 12-September 05

Re: Variables from .txt file and timer/interval

Posted 05 May 2006 - 02:41 AM

simply fantastic :D thanks a lot Pio!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1