A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: look for external .swf files without loading them

  1. #1
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601

    look for external .swf files without loading them

    the title says all...

    what i want:
    instead of using loadMovie("hello.swf") i just want to look if the file "hello.swf" exists... and then perform an action if it's true (the file is here), and another if it's false (the file is not here).

    thanks

  2. #2
    Senior Member devnull_2k's Avatar
    Join Date
    Oct 2001
    Location
    Limehouse, Ontario - Never heard of it? Not surprised.
    Posts
    784
    Well, you can't exactly check with flash alone, but here is an idea. You do have to load it though.

    You can check to see that the movie doesn't exist in a roundabout way. Check:

    code:

    //load movie into a clip that checks to see if it exists
    mc.loadMovie("hello.swf");

    //check to see if movie is loaded
    if(mc.getBytesLoaded() >= mc.getBytesTotal())
    {
    if(mc._totalframes == 0)
    //movie doesn't exist
    else
    //movie does exist, do something
    }



    Another idea would be to query a php script (php has access to the filesystem). So use LoadVars to query the script (which checks to see if the file exists), and base the actions you take upon the response.
    Last edited by devnull_2k; 08-06-2003 at 01:10 PM.
    The future belongs to those who prepare for it today.

  3. #3
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    thanks for being so fast, devnull...

    i see what you mean with your first idea, but it's almost useless for me... but still, i can load the movies and unload them right after... but it will take forever, since they are numerous and quite big...

    about your second idea, i was thinking about something like that: have an external .txt file with the name of the .swf (here it was called "hello") that contains only a variable that "proves" the existence of the .swf file... is that what you were thinking about?

  4. #4
    Senior Member devnull_2k's Avatar
    Join Date
    Oct 2001
    Location
    Limehouse, Ontario - Never heard of it? Not surprised.
    Posts
    784
    Not exactly. Let me run you through it quickly.

    code:

    //LoadVar for Recieving
    fileCheckR = new LoadVars();
    //this method processes variables upon recieving
    fileCheckR.onLoad = function()
    {
    if(this.fileCheckResponse == true)
    //the file exists, do something
    else
    //no file, do something else
    };

    //LoadVar for Sending
    fileCheckS = new LoadVars();
    fileCheckS.file = "hello.swf"; //this is the file you want to look for
    fileCheckS.sendAndLoad("checkForFile.php", fileCheckR, "GET");



    When you do the sendAndLoad, it hits a php page like this

    http://www.youdomain.com/directory/c...file=hello.swf

    The php script checks to see if the file exists, and prints

    fileCheckResponse=true

    or

    fileCheckResponse=false

    to the page.


    Good question by the way. This is what I come to this forum for.
    The future belongs to those who prepare for it today.

  5. #5
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Couldn't you just store the filenames in an external xml file and update it as and when you add a new file ( I guess you're thinking about loading external sprites / tilesets but want your loader system to be smart, so you don't have to add to it every time you finish an external file, just run through a loop automaticaly ).

    Similar to your external txt file idea, but at least having all the files in a xml file you only have to update that and it's all neat and in one place.

    Hopefully that's some ( Vague ) help.

    Squize.

  6. #6
    Senior Member Olorin's Avatar
    Join Date
    Aug 2000
    Posts
    1,151
    PHP Code:

    <?php

    if (file_exists($filename)){
    echo 
    "filecheck=1&";
    }else{
    echo 
    "filecheck=0&";
    }
    ?>
    That's all you need for the php file, and I think that would be the best solution...

    Olorin

  7. #7
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    thanks both, i'll do some test

    I guess you're thinking about loading external sprites / tilesets
    well, here's the purpose: my fighting game. i want their face to appear in the character selection screen (and be selectionnable of course) ONLY if a file of it exists in the corresponding directory (instead of working again with the character selection screen's code and images each time a character is added).

    > so, basically i want an interactive character selection screen... showing dinamically how many characters are selectionnable.

    note, it's surely for an offline purpose...

  8. #8
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    Originally posted by marmotte
    ...note, it's surely for an offline purpose...
    Really?

    So how would you "update" it if it were offline? And why would loading the MC's be a problem offline? They'll load almost instantly, so checking if it has been loaded ( ie, it exists ) means you don't have to wait. If you're updating then that'll need internet connection, in which case why not PHP or XML?

    Also, i haven't checked this, but the first idea of devnull's made me think. If the file didn't exist, then will a getBytesTotal return 0? And how to check _totalframes, if it doesn't exist at all? Hmm, confusing. Would have to try it out to know, unless devnull knows that those kind of assumptions are valid.
    jonmack
    flash racer blog - advanced arcade racer development blog

  9. #9
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    why would loading the MC's be a problem offline?
    oh, it's not really a problem, i was just wondering if looking for a directory and report all the files inside existed with AS.

    of course, i can load the MCs without problem offline; but already now, due to 3 simultaneous loads, the computer may take 3 or 4 seconds to load them all... imagine when i'll have 20 or more files... and the same thing on a cdrom will be worse :-(

    btw it's ok, i was just wondering if flash alone is able to look into a directory and report file names. it's not the case apparently (how lame to be forced to load a movie in order to know it really exists)... too bad for this one.

    anyway, thanks again

  10. #10
    What you could do is have the person place 2 files when they get a new character..

    player.swf
    player.var

    player.var just a file that says
    haveplayer=true

    Then do a loadvars on each of the files. being its so small shouldnt take as long...

    Nugget

  11. #11
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    yes, that's what i said earlier ^^

    it seems to be a good method for what i want...

  12. #12
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    if it's offline i'd use studioMX or screenWeaver. you can do all those things with these products.
    if it's online i'd include code in my "upload" .php add the name to an index file when i upload the .swf.
    see;
    http://www.yamago.net/components/
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

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