A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Newbie question

Hybrid View

  1. #1
    Senior Member Ecinele's Avatar
    Join Date
    Nov 2002
    Posts
    439

    Newbie question

    Hello
    I have many games for education that I would like to put on the Internet. Of course, I don't want others to be able to download my games and save them to their computer.
    I noticed that some flash content only downloads a player/holder without downloading the flash file itself.
    Can anyone tell me how I can do this?
    Thanks
    Ecinele

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Either use Javascript to check for the current website the game is being viewed in and only display it if it's in your website, OR, like you've already mentioned, make your main SWF file a container for another SWF file which is being loaded in the main SWF file, by using this on your Frame Actions:

    Actionscript Code:
    _root.loadMovieNum("realGame.swf", 0);

    However, if someone decompiles the container SWF file, then they will be able to see that code and locate the real file
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Member
    Join Date
    May 2012
    Posts
    51
    What you need to know is that there's two possible security settings for local playback of SWF files (i.e. from a user's computer): "access local files only" and "access network only." The first option means that a local SWF can load another local file but cannot access anything on the Internet. The second option means that a local SWF has Internet access but cannot read anything on the local computer. The two options are mutually exclusive: an SWF file running locally can access either local files or remote files but not both. The arrangement prevents a downloaded SWF file stealing information from a user's computer.

    The default in Flash Professional is "access local files only." Let say you have two SWF files on your computer:

    C:\Users\Ecinele\Downloads\loader.swf
    C:\Users\Ecinele\Downloads\game.swf

    where loader.swf has no other fuction but load to game.swf. If you double-click on loader.swf, it will have no qualm about loading game.swf, since game.swf is a local file and the SWF file is allowed to load a local file. If you change the publish settings of loader.swf to "access network files only," then loader.swf will refuse to load C:\Users\Ecinele\Downloads\game.swf as that's a security violation. It will only load game.swf if it's hosted only a web server.

    So we're half way there. Now you just need to keep people from running game.swf directly. That should be fairly easy. One way to do it is to just check the first child of stage. If it isn't the loader, then jump into an infinite loop.

  4. #4
    Senior Member Ecinele's Avatar
    Join Date
    Nov 2002
    Posts
    439
    Thanks for your detailed explanation.
    Could you create a sample file of what you are describing here with the code?
    Thanks
    Ecinele

  5. #5
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    In your container FLA file, go to File->Publish Settings... [CTRL+SHIFT+F12], switch to Flash tab. Look for Local playback security: and change it from Access local files only to Access network only, and press OK to save changes. Click on your Frame (Frame 1), open Actions Panel for that Frame [F9], and type this:

    - Actionscript 2.0 -

    Actionscript Code:
    createEmptyMovieClip("container_mc", 0);
    container_mc.loadMovie("game.swf");

    - Actionscript 3.0 -

    Actionscript Code:
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.display.MovieClip;

    var gameURL:String = "game.swf";
    var loader:Loader = new Loader();
    loader.load(new URLRequest(gameURL));
    var emptyMC:MovieClip = new MovieClip();
    addChild(emptyMC);
    emptyMC.addChild(loader);

    Publish this as container.swf file (Test Movie) and upload it to your server (i.e. your website). Now, in your game itself, click on a Frame on Frame 1, open Actions Panel [F9] and type this:

    - Actionscript 2.0 -

    Actionscript Code:
    if(_root != this){
        i = 0;
        while(i == 0){
            // crash
        }
        unloadMovie(this);
    }

    - Actionscript 3.0 -

    Actionscript Code:
    if(this.loaderInfo.loader == null){
        var i = 0;
        while(i == 0){
            // crash
        }
        stage.removeChild(root);
    }

    Upload your game SWF file to your server as well, after publishing it. Now, go to your folder where both the container and game SWF files are, and first open your game SWF file. You'll notice how it crashes (you'll have to wait 15 seconds by default before being able to close it). Then, open your container SWF file and notice how your game is NOT loaded into it. However, there's one slight problem, the solution provided by cleong (props for the great idea, btw ) only works with local SWF file preview, like when you open a .SWF file in Flash Player, like you did just now, these security rules are however ignored when tested online, so someone could simply create a .HTML file and embed your game in it, open the HTML file in their browser and play the game (while having both SWF files on their computer) without this solution working.

    In that case, what you can do is to check for the URL path of the SWF file, and check if it's being played from your site or not (code goes on Frame 1, you don't have to remove the previous code, but you can if you want to):

    - Actionscript 2.0 -

    Actionscript Code:
    // say, if your website's full URL path is:
    // [url]http://www.mywebsite.com/[/url]
    // only type your website's name + the country code, like below
    yourWebsite = "mywebsite.com";

    myURL = flash.external.ExternalInterface.call("function(){ return window.location.href; }");
    basename = myURL.split("/");

    if(basename[2] != yourWebsite && basename[2] != "www."+yourWebsite){
        i = 0;
        while(i == 0){
            // crash
        }
        unloadMovie(this);
    }

    - Actionscript 3.0 -

    Actionscript Code:
    // say, if your website's full URL path is:
    // [url]http://www.mywebsite.com/[/url]
    // only type your website's name + the country code, like below
    var yourWebsite:String = "mywebsite.com";

    var myURL:String = flash.external.ExternalInterface.call("function(){ return window.location.href; }");
    var basename:Array = myURL.split("/");

    if(basename[2] != yourWebsite && basename[2] != "www."+yourWebsite){
        var i = 0;
        while(i == 0){
            // crash
        }
        stage.removeChild(root);
    }

    Some people have encountered bugs with ExternalInterface in some browsers, but with other javascript codes, so I'm pretty sure this code will work on all major browsers.

    Hope this helps
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

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