Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Set Action based on Value from txt File.

Posted on 2003-10-24
8
Medium Priority
?
229 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 375 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
Suggested Courses

773 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