Solved

Set Action based on Value from txt File.

Posted on 2003-10-24
8
181 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
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.

743 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

11 Experts available now in Live!

Get 1:1 Help Now