Solved

Set Action based on Value from txt File.

Posted on 2003-10-24
8
190 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:valentin_v
  • 4
  • 4
8 Comments
 
LVL 5

Accepted Solution

by:
Calron earned 125 total points
ID: 9614382
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

0
 

Author Comment

by:valentin_v
ID: 9616201
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.
0
 
LVL 5

Expert Comment

by:Calron
ID: 9616260
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.
0
 

Author Comment

by:valentin_v
ID: 9616645
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.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:Calron
ID: 9616884
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.
0
 

Author Comment

by:valentin_v
ID: 9618515
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
0
 
LVL 5

Expert Comment

by:Calron
ID: 9618905
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
0
 

Author Comment

by:valentin_v
ID: 9626842
Got it

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

Thanks for help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now