how to load random variables from txt file in one dynamic text in swishmax
A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: how to load random variables from txt file in one dynamic text in swishmax

  1. #1
    Member
    Join Date
    May 2016
    Posts
    37

    how to load random variables from txt file in one dynamic text in swishmax

    hello,all


  2. #2
    Member
    Join Date
    May 2016
    Posts
    37
    please help

  3. #3
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,747
    Here's the page to refer to for loadVariables https://help.adobe.com/en_US/as2/ref...c47f-7fec.html
    For anything more could you upload your file?
    .

  4. #4
    Member
    Join Date
    May 2016
    Posts
    37
    my file
    Attached Files Attached Files

  5. #5
    Member
    Join Date
    May 2016
    Posts
    37
    excuse me this is my file
    Attached Files Attached Files

  6. #6
    Member
    Join Date
    May 2016
    Posts
    37

  7. #7
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,747
    I'm having trouble working swishmax. Could you share all the code in a text file?
    .

  8. #8
    Member
    Join Date
    May 2016
    Posts
    37
    the button code is
    PHP Code:
    on (press) {
        var 
    i:int Math.randomRange(1,30)
        if ( 
    ==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 ( 
    ==2){
        
    question question2 
        this
    .loadVariables("settings.txt");
    }else if ( 
    ==3){
        
    question question3 
        this
    .loadVariables("settings.txt");
    }


    settings.txt is:

    PHP Code:
    &question1put here  any question &
    &
    question2put here any question &
    &
    question3put here  any question 
    Last edited by kofa; 11-20-2017 at 04:50 AM.

  9. #9
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,701
    Hi,

    I don't have swishmax but this is one way to do it in as3, perhaps you can get something from it.

    PHP Code:
    import flash.net.URLLoader;
    import flash.net.URLRequest;

    var 
    loader:URLLoader = new URLLoader(new URLRequest("settings.txt"));
    loader.addEventListener(Event.COMPLETEvarsLoaded);

    function 
    varsLoaded(e:Event):void
    {
        
    e.target.removeEventListener(Event.COMPLETEvarsLoaded);

        var 
    variables:URLVariables = new URLVariables(loader.data);

        var 
    minNumber:int 1;
        var 
    maxNumber:int 30;
        var 
    numberRange:int maxNumber minNumber;

        var 
    i:int Math.ceil(Math.random() * numberRange) + minNumber;
        
    trace("Question " i);

        var 
    question variables["question" String(i)];
        
    trace(question);

        
    myTextField.text String(question);

    Code:
    question1= put here  any question 1
    &question2= put here any question 2
    &question3= put here  any question 3
    &question4= put here any question 4
    &question5= put here  any question 5
    &question6= put here any question 6
    &question7= put here  any question 7
    &question8= put here any question 8
    &question9= put here  any question 9
    &question10= put here any question 10
    &question11= put here  any question 11
    &question12= put here any question 12
    &question13= put here  any question 13
    &question14= put here any question 14
    &question15= put here  any question 15
    &question16= put here any question 16
    &question17= put here  any question 17
    &question18= put here any question 18
    &question19= put here  any question 19
    &question20= put here any question 20
    &question21= put here  any question 21
    &question22= put here any question 22
    &question23= put here  any question 23
    &question24= put here any question 23
    &question25= put here  any question 25
    &question26= put here any question 26
    &question27= put here  any question 27
    &question28= put here any question 28
    &question29= put here  any question 29
    &question30= put here any question 30

  10. #10
    Member
    Join Date
    May 2016
    Posts
    37
    sorry, not working


  11. #11
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,701
    Hi,


    I didn't think it would work with swishmax as it is AS3, I don't use swishmax, but it would give you a better way of getting the correct random line for you question.

  12. #12
    Member
    Join Date
    May 2016
    Posts
    37
    ok

    what is the way to load random questions form external txt file ??????
    please attach swishmax file

  13. #13
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,701
    HI,

    I repeat , I do not use or have swishmax, bu you are taking the long way round to choose your random question with all the if statements.

  14. #14
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,747
    Looking at your original code, there are several issues to look at. First of all, the text you're loading.
    Code:
    &question1= put here  any question &
    &question2= put here any question &
    &question3= put here  any question &
    This should be this instead:
    Code:
    question1=put here any question1&question2=put here any question2&question3=put here any question3
    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:
    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");
    }
    }
    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) {
        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 
    }
    }
    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 example
    Code:
    var param_interval = setInterval(checkParamsLoaded, 100);
    This creates a variable to store the interval. It will call the function checkParamsLoaded every 100 milliseconds.


    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:
    Code:
    on (press) {
    	this.loadVariables("settings.txt");
    	_root.param_interval = setInterval(_root.tFun, 100);
    }
    On the root timeline this is the rest of the code:
    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;
    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.

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center

Poll by Flashkit.com