A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: hide "undefined" message in dynamic text box

  1. #1
    Member
    Join Date
    Nov 2005
    Posts
    35

    hide "undefined" message in dynamic text box

    Hi, I'm loading external text using:

    var externalData:LoadVars = new LoadVars();
    externalData.onLoad = function(){
    scopy_txt.text = externalData.shomecopy;
    }

    externalData.load("shomecopy.txt");

    There are a few .txt files that haven't been created yet, so naturally the box reads "undefined". However, in the files that are loading, I'm still getting an "undefined" message before the actual text shows up. How can I hide/prevent this?

    I tried: if (scopy_txt.text = "undefined"){
    scopy_txt.text.setVisible(false);
    } else{ scopy_txt.text.setVisible(true);
    }

    and it didn't work

    here's the site:

    http://www.surroundings-rogersgallery.com/

  2. #2
    Senior Member corky§urprise's Avatar
    Join Date
    Jun 2005
    Posts
    346
    When declaring a variable you say =
    When requesting a variable you say ==

    _root.scopy_txt="text"
    _root.scopy_txt=="text"

    change your script to

    if (scopy_txt.text == "undefined"){
    scopy_txt.text.setVisible(false);
    } else{ scopy_txt.text.setVisible(true);
    }

    Hope it helps

  3. #3
    Member
    Join Date
    Nov 2005
    Posts
    35
    Thanks for the help, but that didn't work either.

  4. #4
    Senior Member ellings's Avatar
    Join Date
    Sep 2001
    Posts
    155
    Try undefined without "". Undefined is not a string.

    /Per-Henrik

  5. #5
    Member
    Join Date
    Nov 2005
    Posts
    35
    no go, it's still flashing "undefined" before loading the text.

  6. #6
    Uses MX 2004 Pro Quixx's Avatar
    Join Date
    Nov 2004
    Location
    U.S.
    Posts
    877
    You can use a boolean variable to determine if the text is loaded and display the text if it's there, or nothing at all if the load fails.

    Code:
    var externalData:LoadVars = new LoadVars();
    externalData.onLoad = function(success:Boolean) {
    	if (success) {
    		scopy_txt.text = this.shomecopy;
    	}
    };
    externalData.load("shomecopy.txt");

  7. #7
    Member
    Join Date
    Nov 2005
    Posts
    35
    It seems to work for the main movie text - when you first come to the scene, but not for the .txt files loaded from the external swfs.

    My external swf's have three frames (first two for preloader) and the third loads the external text:

    this.onEnterFrame = function(){
    _root.scopy_txt.text = _root.externalData.sbathcopy;
    }
    _root.externalData.load("sbathcopy.txt");

    should I be adding a Boolean here here also?

  8. #8
    Uses MX 2004 Pro Quixx's Avatar
    Join Date
    Nov 2004
    Location
    U.S.
    Posts
    877
    Quote Originally Posted by lotsamottsa
    It seems to work for the main movie text - when you first come to the scene, but not for the .txt files loaded from the external swfs.

    My external swf's have three frames (first two for preloader) and the third loads the external text:

    this.onEnterFrame = function(){
    _root.scopy_txt.text = _root.externalData.sbathcopy;
    }
    _root.externalData.load("sbathcopy.txt");

    should I be adding a Boolean here here also?
    Yes, you'd need to use it for each time you load in a text file. Out of curiosity, why are you using an onEnterFrame event handler in your above post, and not .onLoad?

  9. #9
    con[fuzed] designer
    Join Date
    Jan 2003
    Location
    UK
    Posts
    314
    a way i have got round this before is by setting a default loading value into the text area like for example "loading xml data", this is replaced when the loaded data becomes available.

  10. #10
    Member
    Join Date
    Nov 2005
    Posts
    35
    yaaaayyy that worked thanks Quixx! I didn't realize I needed to repeat the whole code in each external swf. I was refering to the external swf using this.onEnterFrame because this.onLoad didn't load any text at all, but now I realize using _root.externalData.onLoad makes more sense.

    Thank you so much for your help and thank you all for your time!!!

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