Frage

Greatings!

I have yet another question concerning the loading of a .swf inside a existing one.

In my game. I have a introduction screen in which I load another .swf (which is a movie). This all works fine and the URLRequest is this:

request = new URLRequest("Movie.swf");

As I said, this works fine. However when I copy my game.swf and movie.swf to a USB stick. (I put them in the same directory to prevent other issues). It doesn't seem to find the movie.swf.

Now I know that it has to do with the path given in the URLRequest and/or the publish settings. But I do not know how to make this so that it searches in the same directory as the game.swf is in.

I hope you guys have an answer for this issue.

Thanks in advance,

Matti.

War es hilfreich?

Lösung

Matti, I believe Lukasz's comment is correct about it being a security error.

You can avoid this security error by embedding Movie.swf instead of using a Loader. If you do this, then at compile-time the Movie.swf needs to sit next to the Game.as file, and it will be included in the Game.swf (no need to deliver both files, just Game.swf).

The syntax is:

package
{
  import flash.display.Sprite;

  public class Game extends Sprite
  {

    [Embed(source="MyMovie.swf")]
      private var myMovieClass:Class;

    private var myMovie:DisplayObject;

    public function Game():void
    {
      myMovie = new myMovieClass();

      // Technically myMovie is now a Loader, and once
      // it's loaded, it'll have .content that's a
      // MovieClipLoaderAsset, and .content.getChildAt(0)
      // will be your MyMovie.swf main timeline.
    }
  }
}

Alternately, if you embed it as mimeType="application/octet-stream", you can get the bytes of the SWF and use it in your existing Loader's .loadBytes() method:

package
{
  import flash.display.Sprite;
  import flash.utils.ByteArray;

  public class Game extends Sprite
  {

    [Embed(source="MyMovie.swf", mimeType="application/octet-stream")]
      private var movieBytes:Class;

    private var myMovie:DisplayObject;

    public function Game():void
    {
      // Treat this loader the same as your current loader,
      // but don't call .load(url), call loadbytes():
      var l:Loader = new Loader();
      l.loadBytes(new movieBytes() as ByteArray);
    }
  }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top