A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Actionscript problem

  1. #1
    Junior Member
    Join Date
    Mar 2015
    Posts
    2

    Actionscript problem

    I have a script that loads variables from a text file into two dynamic text fields . It works and the values display in the dynamic text boxes on screen.

    My difficulty comes when I try and find the length of the value in the dynamic text field. It is the same no matter what the length of the string is and the value is 20 both times.

    The text file:

    &word1=This is a string&
    &word2=This is a second String&

    Actionscript

    loadVariables("text.txt","");

    myVar1 = _root.word1;
    trace (myVar1.length);

    myVar2 = _root.word2;
    trace (myVar2.length);


    The names of the dynamic instances are text1 and text2. The name of the dynamic variables is word1 and word2

    What am I doing wrong?

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Maybe try using loadVars in stead as you know when and if the file has loaded correctly.
    PHP Code:
    var getVars:LoadVars = new LoadVars();
    getVars.load("text.txt",_root);
    getVars.onLoad = function(success)
    {
        if (
    success)
        {
            var 
    myVar1 this.word1;
            
    text1.text myVar1;
            
    trace(myVar1.length);
            
            var 
    myVar2 this.word2;
            
    text2.text myVar2;
            
    trace(myVar2.length);
        }
    }; 
    Or if you wish to continue using loadVariables or loadVariablesNum, take a look here, http://www.actionscript.org/resource...cts/Page1.html

  3. #3
    Junior Member
    Join Date
    Mar 2015
    Posts
    2
    That's brilliant. Thank you! It works perfectly!

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