views:

417

answers:

3
+1  Q: 

Bookmark a page

How can we bookmark a page on clicking a button or a link button in flex using actionscript

A: 

You'll have to use javascript for that. Just create a javascript function to bookmark a page in your html file that is hosting the swf and then call that function from inside the swf using ExternalInterface.

Here's an example of a javascript function for bookmarking: http://labnol.blogspot.com/2006/01/add-to-favorites-ie-bookmark-firefox.html

Here's the Flex docs on how to use ExternalInterface: http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001009.html

Christophe Herreman
A: 

AFAIK, you can't do that from actionscript directly. However, you can invoke javascript from actionscript unsing the ExternalInterface class, and the web is teeming with javascript functions to create bookmarks. Take a look at this, for example (I have not tested it).

David Hanak
+1  A: 

A working example based on the information in previous answers:

bookmarks.js (add this to your html-template directory):

 function CreateBookmarkLink(title, url) 
 {
    if (window.sidebar) { // Mozilla Firefox Bookmark
     window.sidebar.addPanel(title, url,"");
    } else if( window.external ) { // IE Favorite
     window.external.AddFavorite( url, title); }
    else if(window.opera && window.print) { // Opera Hotlist
     return true; }
 }

Then add this line to index.template.html:

<script src="bookmarks.js" language="javascript"></script>

Now you have javascript code "wrapping" your Flex application which can be called by this code (bookmarks.mxml):

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
     <![CDATA[
      public function AddBookmark() : void
      {
                ExternalInterface.call("CreateBookmarkLink", 
                   "Stack Overflow", 
                   "http://www.stackoverflow.com");
      }
     ]]>
    </mx:Script>
    <mx:Button x="10" y="10" label="Bookmark!" click="AddBookmark()"/>
</mx:Application>

Tested on IE.

Assaf Lavie
This Firefox method doesn't work because it forces the bookmark to open in the sidebar - which is not the desired outcome.
Eric Caron