A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Very simple function, variable are not setting!

  1. #1
    Senior Member
    Join Date
    Jul 2002
    Posts
    119

    Very simple function, variable are not setting!

    Hi, this is infuriating me.

    I have the below function which works with

    Code:
    function loadText(){
    	textImport = new LoadVars();
    	textImport.onLoad = onText;
    	textImport.load("content.txt");
    		function onText() {
    		textBox.htmlText = textImport.aboutUs;
    		}
    }
    But when i set a variable like below it doesnt work. The text box comes back as "undefined". Ultimately i want to pass through some arguments through the function, but i just cant work out why its not passing through this variable. Iv tryed single quotes, double quotes and no luck!

    Code:
    function loadText(){
    	 var jgm = aboutUs;
    	textImport = new LoadVars();
    	textImport.onLoad = onText;
    	textImport.load("content.txt");
    		function onText() {
    		textBox.htmlText = textImport.jgm;
    		}
    }
    Thanks for your time and any help greatly appreciated.

  2. #2
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    LoadVars variables are defined in the file being loaded as:

    varName=varValue&varName2=someOtherValue

    the var you declared:
    var jgm
    is not eqivelent to
    textImport.jgm

    unless you defined it
    textImport.jgm = aboutUs
    but then there is no point using LoadVars and the variable is being defined iunternally anyway.

    Now if aboutUs is some variable that is being loaded, you are trying to access it too early. You would have to access it after the load completed as in:

    function onText() {
    textImport.jgm = textImport.aboutUs
    textBox.htmlText = textImport.jgm;
    }

    but at that point why bother when you could just:
    function onText() {
    textBox.htmlText = textImport.aboutUs;
    }

    So it might just be that I am not totaly understanding what you are trying to do with this.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  3. #3
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    that because jgm is not being set after the variables have been loaded. u are trying to assign aboutUs to jgm before.. modify you code:

    Code:
    function loadText(){
    	textImport = new LoadVars();
    	textImport.onLoad = onText;
    	textImport.load("content.txt");
    		function onText() {
                     this.jgm = this.aboutUs;
    		textBox.htmlText = this.jgm;
    		}
    }
    P.S what r u trying to do anyway? The first function looks fine for your needs...
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  4. #4
    Senior Member
    Join Date
    Jul 2002
    Posts
    119
    Im still getting an "undefined" message.

    P.S what r u trying to do anyway?
    The function is there to load different parts of the text file for different sections of the site. I want to pass through a variable that has the name of the part in the text file the example i am trying below has the variable "aboutUs".



    This code is on the first keyframe of the movieclip.

    Code:
    function loadText(path){
    	textImport = new LoadVars();
    	textImport.onLoad = onText;
    	textImport.load("content.txt");
    		function onText() {
                     this.jgm = this.path;
    		textBox.htmlText = this.jgm;
    		}
    }
    Then the below is on a keyframe further up the timeline within the same movie clip.

    Code:
    loadText("aboutUs");

    Thanks.
    Last edited by juanmac; 06-30-2006 at 10:17 AM.

  5. #5
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    What does the text file you are loading look like?
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  6. #6
    Senior Member
    Join Date
    Jul 2002
    Posts
    119
    Its like this:

    Code:
    aboutUs=<p>PMS is an Aberdeen based dynamic and creat............</p>
    
    &aboutUs2=<p>Producers, editors, animators, cameramen  all bring their own specific talents................</p>

  7. #7
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    see if :
    function onText() {
    textBox.htmlText = this[path];
    }

    works. Might be messing up because you are passing the function a string when trying to access a variable name.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  8. #8
    Senior Member
    Join Date
    Jul 2002
    Posts
    119
    Thats working. FANTASTIC!

    Thanks very much!

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