Set Action based on Value from txt File.

I want to make a drum rotate based on value that will get from txt file.

Lets say if value in TXT file is 0. Drum will not roate.
If value in TXT file is 1 drum will rotate.

TXT would reside in same folder.

And also, how can I get a new values in Flash Movie every few seconds. So if I have a Flash movie that reads a TXT file, and I change that TXT file, I want FLASH to check for TXT and update itself in real time.

Thanks in Advance.

Valentin
valentin_vAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CalronCommented:
I don't quite get it, you want the fla to change according to the text file or do you want to have a movieclip whose behavior changes depending on the value of the text file?

On how to load a text file have a look at this tutorial:

http://www.flashkit.com/tutorials/Actionscripting/Basic/Reading_-Brett_Ta-139/index.php 


Then to change the behavior of a movieclip you will need two things in th emovieclip:

let's say frames 1 - 10 contain the animation you want to show if the text contains 0
frames 11-20 contain the animation for text file containin 1

you need to add either stop(); or gotoAndPlay(1) in frame 10 depending whether you want the animationrepeated or just shown once. Same for the second animation.
Then in the first fram e add somehting like this:

Load the txt file and set the variable animationsetting according to the value you read.
if (this.animationsetting == 1) gotoAndPlay(11);  // this checks if the variable animationsetting is set to 1 and if so plays that animation

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
valentin_vAuthor Commented:
Basically I loaded a txt file with variable &run

Statement is

if (run == 1)  gotoAndPlay(11);  
else
if (run == 0)  gotoAndPlay(2);  

And it works, I put 1 as value, it will play rest as wanted.
If I put 0 it will not go beyond frame 1

For this to work when changing variable value, I need to restart movie every time.

I want while movie is working to check if variable has changed from 0 or 1. If it did, it will go to frame 11. Basically REAL TIME checking if variable &run changed.
CalronCommented:
If you want it to do the runtime check you have to realod the textfile. So you have to call the load command again to refress the run parameter. That way it should work at runtime.
The parameter only changes when the text file is reloaded with a different value in it.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

valentin_vAuthor Commented:
I got it to work on local computer, but when I put it on server, it will not load variable again.

I have put load variable at the end to load it with a new value, but on server will not repond. Variable that is loaded with movie will stay.

CalronCommented:
On a server you will run into the problem of the files being cached. So it could be that the cached file is being reloaded. To get around this you might have to add some random number. I am not sure if this works with txt files, but this is what I did when loading values from a php file:

load("myphp.php?num=" + random(10000));

It should probably work for text files as well and that way the file should be reloaded every time.
valentin_vAuthor Commented:
I have created run.php and tried
load("run.php?num=" + random(10000)); at the end of movie to load it , and still it will not pick up new value.

run.php content:
<?php
echo ("&run=0");
?>

or

<?php
echo ("&run=1");
?>

Other value in movie

if (run == 1)  gotoAndPlay(11);  
else
if (run == 0)  gotoAndPlay(2);  

I guess its only caching of files because if I close brower and load it again, animation will change, it I just click on Refresh will not.

Is there another way to prevent caching
CalronCommented:
Have a look at these two PAQ's they discuss the same problem and use pretty much the same solution:

http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q_20538312.html
http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q_20540541.html
valentin_vAuthor Commented:
Got it

loadVariablesNum("run.txt?nocache=" + new Date().getTime(),0);

Thanks for help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.