Looking at your original code, there are several issues to look at. First of all, the text you're loading.
This should be this instead:Code:&question1= put here any question & &question2= put here any question & &question3= put here any question &
The & symbol is for separating each section into different variables. The only reason I would do it would be to make it more readable. It's still wasteful. Still, having the extra space after the = sign will show up.Code:question1=put here any question1&question2=put here any question2&question3=put here any question3
This is messy in many ways. First of all, the loadVariables function loads all the vars into the object you target. Because of this you should only run it once in this case.Code:on (press) { var i:int = Math.randomRange(1,30) if ( i ==1){ // my request is when i = 1 , the var which named (question ) load question number 1 from settings.txt and when i = 2 ,question number 2 and so on question = question1 this.loadVariables("settings.txt"); }else if ( i ==2){ question = question2 this.loadVariables("settings.txt"); }else if ( i ==3){ question = question3 this.loadVariables("settings.txt"); } }
The next part is loading external data take a bit. So you need to set up an interval. This is basically a function that keeps activating a target function over the time you set. For exampleCode:on (press) { this.loadVariables("settings.txt"); var i:int = Math.randomRange(1,30) if ( i ==1){ // my request is when i = 1 , the var which named (question ) load question number 1 from settings.txt and when i = 2 ,question number 2 and so on question = question1 }else if ( i ==2){ question = question2 }else if ( i ==3){ question = question3 } }
This creates a variable to store the interval. It will call the function checkParamsLoaded every 100 milliseconds.Code:var param_interval = setInterval(checkParamsLoaded, 100);
After moving things around, this is what I came up with. First I divided the code into two different areas. One is on the button and the other is on the base timeline. For the button, this is my code:
On the root timeline this is the rest of the code:Code:on (press) { this.loadVariables("settings.txt"); _root.param_interval = setInterval(_root.tFun, 100); }
I also added another variable to be loaded from the settings.txt file: "&done=done" This is good for indicating that the file has been loaded.Code:function randRange(min:Number, max:Number):Number { return Math.floor(Math.random()*(max-min+1))+min; } function tFun() { trace("-=-=-"); trace("-"+btn["question"+randRange(1,3)]+"-"); if (btn.done == "done") { clearInterval(param_interval); } } var param_interval;
In the end, I used https://help.adobe.com/en_US/as2/ref...c47f-7fec.html as a reference for what I was looking at. I also was using flash instead of swishmax. swishmax is giving me trouble to set up.




Reply With Quote