Can I make the swf address a real url and not use #?

Is it possible to do swfaddress or any script to allow flash to change the display URL (without actually navigating to a new page) in the browser to whatever I choose? I understand that swfaddress makes the URL always refer to the original SWF file, which is great, but the web template I'm working on will always load swf, no matter what URL you visit on site. The difference will be that the content immediately loads. When you navigate through flash memory to different articles, I want the URL to be able to be changed as if it were an html page, since I will have the corresponding html content for SEO purposes. This will be a large site, and I want to optimize it for sharing and searching.

As an example, not "site.com/#/news-just-in", I need the URL "site.com/2011/3/news-just-in".

Is it possible?

+3
source share
2 answers

You can do this, but only in browsers that support the new HTML5 history API . You will need to use ExternalInterfaceJavaScript to interact with the layer. The flash side of things might look like this:

package {
  import flash.display.Sprite;
  import flash.events.MouseEvent;
  import flash.external.ExternalInterface;
  import flash.text.TextField;
  import flash.text.TextFieldAutoSize;

  public class Test extends Sprite {
    protected var _text:TextField;

    function Test() {
      var b:Sprite = new Sprite;
      b.graphics.beginFill(0xff0000);
      b.graphics.drawRect(0, 0, 32, 32);
      b.graphics.endFill();
      b.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void {
        pushState('/test/foo');
      });
      addChild(b);

      b = new Sprite;
      b.x = 64;
      b.graphics.beginFill(0x0000ff);
      b.graphics.drawRect(0, 0, 32, 32);
      b.graphics.endFill();
      b.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void {
        pushState('/test/bar');
      });
      addChild(b);

      _text = new TextField();
      _text.autoSize = TextFieldAutoSize.LEFT;
      _text.y = 64;
      addChild(_text);

      if (ExternalInterface.available) {
        ExternalInterface.addCallback('onPopState', onPopState);
        ExternalInterface.call('test.onReady');
      } else {
        _text.text = 'external interface not available';
      }
    }

    protected function onPopState(path:String):void {
      _text.appendText("flash onPopState: " + path + "\n");
    }

    protected function pushState(path:String):void {
      _text.appendText("flash pushState: " + path + "\n");
      ExternalInterface.call('history.pushState', null, null, path);
    }
  }
}

And the JavaScript side might look like this:

<!DOCTYPE html>
<html>

<body>
  <script type="text/javascript">
  if (!!(window.history && history.pushState)) {
    var test = {
      onPopState: function(event) {
        if (this.embed) {
          this.embed.onPopState(location.pathname);
        }
      },

      onReady: function() {
        var embed = document.getElementById('flash');
        this.embed = embed.getElementsByTagName('object')[0] || embed;
        this.embed.onPopState(location.pathname);
      }
    };

    window.addEventListener('popstate', function(event) {
      test.onPopState(event);
    }, false);
  } else {
    alert('This browser does not support the history API');
  }
  </script>
  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
          id="flash" width="780" height="420">
    <param name="movie" value="test.swf" />
    <!--[if !IE]>-->
    <object type="application/x-shockwave-flash"
            data="test.swf" width="780" height="420">
    <!--<![endif]-->
      <p>Flash is required</p>
    <!--[if !IE]>-->
    </object>
    <!--<![endif]-->
  </object>
</body>

</html>

This example onPopStateis called whenever the path changes, and pushStateis called to change the URL. You can click the red and blue fields in the example to change the URL from Flash.

, -, API . JS, Flash- , . , ​​ History.js - , - .

+5

- , , :

/*
Provides the deep linking value without the query string.
*/
public static function getPath():String {
    var value:String = SWFAddress.getValue();
    if (value.indexOf('?') != -1) {
        return value.split('?')[0];
    } else if (value.indexOf('#') != -1) {
        return value.split('#')[0];
    } else {
        return value;
    }

"#" SWFAddress.js SWFAddressOptimizer.js, .

, (, "3" ), , .

0

All Articles