SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast ptolemy's Avatar
    Join Date
    Feb 2002
    Location
    Geneva, Switzerland
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Using loadVariables for content: is it suitable?

    I'm creating a web site for a student society at my university. I have constructed the site entirely in Flash 5.0 and for ease of maintenance, I have created movie clips that will display content from several text files on the server. This simplified things greatly as it externalized content. My main concern now is whether it is suitable or not? Has anyone done this in the past and run into a deadend?

    Matt

  2. #2
    Photoshop Ninja jonnya's Avatar
    Join Date
    Jan 2002
    Location
    Birmingham UK
    Posts
    733
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, very suitable. I have used this technique a number of times, and it works very well. Also there's the fact that a non-designer without Flash can update the site by just changing the text documents is a nice feature of a site built like this.
    Jonnya Freelance Creative
    UK Freelance designer and web developer
    Website | Portfolio | Photoshop Tips

  3. #3
    ...
    Join Date
    Jan 2002
    Location
    London, UK
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ptolemy,

    Provided your sites not going to get multiple hits per second loading from text files works great, its always a good idea to prevent the file from caching tho.

    Here's a well used function for loading external file content into Flash without it caching.

    Frame 3
    PHP Code:
    function noCache (urltargetstring) {
        if (
    url.indexOf("?") == -1) {
            eval(
    targetstring).loadVariables(url add "?time=" add getTimer(), "");
        } else {
            eval(
    targetstring).loadVariables(url add "&ztime=" add getTimer(), "");
        }
    }
    _level0.noCache("pathToYour/textFile.txt""_level0"); 
    Frame 5
    PHP Code:
    if (page1 == null){
        
    _root.gotoAndPlay(4);
    }
    else {
        
    _root.play();

    textFile contents
    <snip>
    page1=Blah Blah Blah Blah....
    </snip>

  4. #4
    SitePoint Enthusiast ptolemy's Avatar
    Join Date
    Feb 2002
    Location
    Geneva, Switzerland
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's great! Thanks for the tips guys

  5. #5
    Non-Member Nancy's Avatar
    Join Date
    Oct 1999
    Location
    panhandle of Nebraska
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a solution other than PHP, since that is not available.

    Thanks,
    Nancy

  6. #6
    ...
    Join Date
    Jan 2002
    Location
    London, UK
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Which solution are you asking about? caching?

  7. #7
    Non-Member Nancy's Avatar
    Join Date
    Oct 1999
    Location
    panhandle of Nebraska
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes a solution for browser caching.

    Obviously I didn't do enough searching before posting, as I see this can be quite a problem.

    I am wanting to update the variables contained in a text file. It appears your initial response to ptolemy refers to PHP, which is not an option for me at the moment. I also have some jpg images loading with the loadmovie in AS, which also get cached.

    It seems everything works great on my PC, but not when things are on a server.

    Thanks,
    Nancy

  8. #8
    ...
    Join Date
    Jan 2002
    Location
    London, UK
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's a couple of examples using a custom actionscript function called noCache - all you need to change is the path to the text file or level if your using the F5 version.

    In these examples the stopCache.txt file uses this text:

    someValue=blah blah blah


    Code:
    // Flash 5 version
    
    // Frame 1
    function noCache(targetURL, targetstring) {
    	var unique = Math.round(Math.random() * 10000000);
    	// test if any query string values are present
    	if (targetURL.indexOf("?") == -1) {
    		this[targetstring].loadVariables(targetURL + "?u=" + unique, "");
    	} else {
    		this[targetstring].loadVariables(targetURL + "&u=" + unique, "");
    	}
    }
    
    // load text file data into Flash
    noCache("http://localhost/Flash/stopCache.txt", "_level0");
    
    // Frame 3
    // test if your text var is loaded
    if (someValue == null){ 
        gotoAndPlay(2); 
    } 
    else { 
        trace(someValue);
    } 
    stop();
    
    
    // Flash MX version
    
    var c = new LoadVars();
    c.onLoad = showContent;
    function noCache(targetURL) {
    	var unique = Math.round(Math.random() * 10000000);
    	if (targetURL.indexOf("?") == -1) {
    		c.load(targetURL + "?u=" + unique);
    	} else {
    		c.load(targetURL + "&u=" + unique);
    	}
    }
    function showContent() {
    	textField.text = this["someValue"];
    }
    
    // load text file data into Flash
    noCache("http://localhost/Flash/stopCache.txt");

  9. #9
    Non-Member
    Join Date
    Nov 2002
    Location
    Earth
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What's Macromedia's rationale for allowing LoadVars, etc. to only load URLs from the same domain as the flash file?

  10. #10
    ...
    Join Date
    Jan 2002
    Location
    London, UK
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    to only load URLs from the same domain as the flash file?
    No you can load from external sources as well but you'll need to do it with middleware (PHP, ASP etc.) - this is how blog readers like news monkey work.

    There's some examples at http://www.flash-db.com/

    Nancy, here's another example:

    Code:
    var unique = Math.round(Math.random() * 1000000);
    this.loadVariables("pathToYour/textDoc.txt?u=" + unique);

  11. #11
    SitePoint Zealot webQS's Avatar
    Join Date
    Oct 2002
    Location
    Sydney : Australia
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So you can't load another domain's content and access their server side scripts..
    Say for instance there was a script on xyz domain that sent an email. You could then use a Flash form on abc domain to send emails through another domain's web server.

    If you want rendered HTML from another domain's script then the PHP file function can do this. This won't save the other domain's script, of course!

    HTH
    James

    Quote Originally Posted by csn
    What's Macromedia's rationale for allowing LoadVars, etc. to only load URLs from the same domain as the flash file?


Bookmarks

Posting Permissions

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