Bookmark a page - apache-flex

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

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.

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

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).

Related

Flex' VideoDisplay control does not open stream

I'm trying to make VideoDisplay playing media with FlashDevelop. Here's the source of my application:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.events.VideoEvent;
private function pause():void
{
if (moo_player.state == VideoEvent.PLAYING)
moo_player.pause(); else
if (moo_player.state == VideoEvent.PAUSED)
moo_player.play();
}
]]>
</mx:Script>
<mx:Panel>
<mx:VideoDisplay
source="bar.flv"
width="640"
height="480"
maintainAspectRatio="true"
id="moo_player"
autoPlay="true"
doubleClick="pause();"
doubleClickEnabled="true"
/>
</mx:Panel>
</mx:Application>
The problem is when i build application and run it (unfortunately, got no idea how to run it without KMPlayer or Mozilla - Flash Player is a plugin afaik) i got no video. The movie file is in the same directory as application's "Application.flv" one. But if i reload application (within player or browser) a few times, video starts.
So, here are my questions:
what's wrong with VideoDisplay
component and how to fix this
'non-playing'?
what's the better way
to execute application than running
it within movie player or browser?
P.S.: please, do not get mad of my knowledge lacks - i began to use Flex nearly 30 minutes ago.
You should be using Spark components, not MX components. Try this:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:VideoPlayer source="bar.flv" width="640" height="480" />
</s:Application>
There's some issues with video display internally in the component. One of the only flex components that's kind of poorly done in some ways. Please don't let it discourage you from exploring Flex.
Create a custom component that extends it, create a file named CustomVideoDisplay.as with this code:
package
{
import mx.controls.VideoDisplay;
public class CustomVideoDisplay extends VideoDisplay
{
[Bindable]
override public function get source():String
{
return super.source;
}
override public function set source(value:String):void
{
super.source = value;
play();
}
public function CustomVideoDisplay()
{
super();
}
}
}
Then add this into your root <application> tag :
xmlns:local="*"
And for your video component, refer to it as:
<local:CustomVideoDisplay
source="bar.flv"
width="640"
height="480"
maintainAspectRatio="true"
id="moo_player"
autoPlay="true"
doubleClick="pause();"
doubleClickEnabled="true"
/>
Let me know if this doesn't do the trick for you!
Well, i thought: my player will be ran at client-side of web project, and in FireFox that code runs successfully each of seven runs. I think this would be enough for testing and implementation.
Thanks everyone for the trouble-taking!

how to provide functionalities for buttons in flex 3?

i am new to flex. I want to create some buttons and when v click on that button, it should open some images. how to give this functionality in flex builder 3. Thanks for ur time
Try this example if it helps.
The important thing is embedding the image before you use it.Another way of embedding is inline in the mx:Image tag.Please be careful with the path to the location of the image.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
/*in the source put the absolute path(like directory:/folder/image.gif) or the relative path (../image.gif where ../ is your project directory )to the location of your image
*/
[Embed (source="../src/assets/images/image.gif")]
[Bindable]
//this variable of type Class is used to refer to the aboveimage..
public var img:Class;
public function buttonClickHandler():void{
if(image.visible)
image.visible = false;
else
image.visible = true;
}
]]>
</mx:Script>
<mx:Image source="{img}" visible="false" id="image"/>
<mx:Button x="172" y="225" label="Button" id="button" click="buttonClickHandler()"/>
</mx:Application>
hi have a click handler for the button. in the function of click handler handle displaying of image by switching visibilities.have the image embedded in the design before itself. then play with its visibilities on button click.
try going through the examples here.explains about all kind of asset embedding,including sound
http://livedocs.adobe.com/flex/3/html/help.html?content=04_OO_Programming_09.html

Deployed flex applet not processing web service results

When I test my deployed app in a browser the popup window continues to be displayed even after it should be closed. Everything works as expected when debugged in Flash Builder 4.
Following is currently what's happening: the request is sent to my restful web service, which processes the request, (seemingly) the ResultEvent is called which in turn dispatches the profileEvt dynamic event that changes the view state. However, the popup window does not get closed and the applet gets 'stuck.'
Anyone know what could be the problem? Below are the flex applet web service event listeners/handlers:
webService.addEventListener(ResultEvent.RESULT, function(event:ResultEvent):void
{
var rawData:String = String(event.result);
var profileEvt:DynamicEvent = new DynamicEvent("profileSaved", true);
profileEvt.data = JSON.decode(rawData).profile;
dispatchEvent(profileEvt); // Dispatch profile saved event
_progressPopUp.closePopUp();
dispatchEvent(event); // Dispatch submit profile button clicked
});
webService.addEventListener(FaultEvent.FAULT, function(event:FaultEvent):void
{
Alert.show("Could not create profile; please try again later.\n" + event.message, "Status");
_progressPopUp.closePopUp();
});
var params:Object = {"profile" : profile};
try
{
_progressPopUp = PopUpManager.createPopUp(this, com.profs.ui.components.ProgressPopUp, true);
_progressPopUp.eventSource = webService; // Set source of progress events
webService.send(JSON.encode(params));
}
NOTE:
com.profs.ui.components.ProgressPopUp is a custom component; the code for it is below:
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" width="300" height="200" showCloseButton="false" title="Status" creationComplete="init()">
<fx:Declarations></fx:Declarations>
<fx:Script>
<![CDATA[
import mx.managers.PopUpManager;
[Bindable] public var eventSource:Object;
private function init():void
{
PopUpManager.centerPopUp(this);
}
public function closePopUp():void
{
PopUpManager.removePopUp(this);
}
public function completionHandler(event:Event):void
{
closePopUp();
}
]]>
</fx:Script>
<mx:ProgressBar id="progressBar" indeterminate="true" mode="event" source="{eventSource}" complete="completionHandler(event)" verticalCenter="0" horizontalCenter="0"/>
</mx:TitleWindow>
I am not familiar with the com.profs.ui.components.progressPopUp component, but it is possible that the closePopUp() method has a bug in it. You could try to remove the ProgressPopUp directly using the PopUpManager method. For example instead of:
_progressPopUp.closePopUp();
try
PopUpManager.removePopUp(_progressPopUp);
I also don't know off the top of my head what the rules for closures are (i.e. at which point is the _progressPopUp variable copied into the ResultEvent.RESULT event handler. You could try moving that particular event handler below the line where you actually created the _progressPopUp instance.

Calling JavaScript function from Flex 4 web application

I need to call javascript function from Flash 4 based web application. When I run it in Debug mode it runs perfectly but when I make release build or run same application on other machine it does not call JavaScript function.
For testing I am just calling sample Alert function of JavaScript. Can someone help me what I am missing ?
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical" initialize="application1_initializeHandler(event)"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
public function btnLogin_click():void
{
var s:String;
if (ExternalInterface.available)
{
ExternalInterface.call("alert", "Hello World!");
}
else
{
Alert.show("External interface not available");
}
trace(s);
}
protected function application1_initializeHandler(event:FlexEvent):void
{
flash.system.Security.allowDomain("always");
}
]]>
</mx:Script>
<mx:Form>
<mx:FormItem>
<mx:Button id="btnLogin" label="Login" click="btnLogin_click()" />
</mx:FormItem>
</mx:Form>
</mx:Application>
Well, firstly, make sure JavaScript on your testing machine is turned on and then also make sure you are adding your JavaScript file/code after adding swfobject.js file.
I had similar problem but it worked out when I moved swfobject.js at the top of all js includes.
Have you tried a test like (Flex):
ExternalInterface.call("alertFn");
And JS:
function alertFn() {
alert("hello world");
}
?
I've never tried an ExternalInterface call to a native JS function like "alert"...
After digging out the error code 2060 through
Alert.show(e.message)
I figured out that for some reason ExternalInterface.call doesn't work on a file:// and needs http(s)://
So, anybody who is facing this problem, get your yourself a webserver(Apache) or a GAE for testing these kinds of things and save yourself from the "Extreme time wastage":
I was having endless hours of problems using file:// with the Flex
AJAX Bridge.
The AJAX code would fail silently during the SWF initialization
callbacks to the AJAX code. I would then have null values for all of
the SWF root elements.
As soon as I installed a web server and started using http:// localhost
everything worked perfectly.
Extreme time wastage :(
test.mxml
..........
protected function bt1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
ExternalInterface.call("callUnity");
}
.js
....
function callflex(){
alert("got it");
}

Flex: weird question, can't access application property in init event of SWFLoader

Very weird problem, I am new to AS, but I have to say it's hard to comprehend AS is a modern language:
private function completed():void
{
trace("completed.");
var player:Object = (loader.content as SystemManager).application as Object;
player.playVideo();
player.setSize(200,300);
}
SWFLoader id="loader" horizontalCenter="0" width="100%" height="362" source="http://localhost:8000/testflv1.swf" init="completed()"
What I want to do is embed a swf in another parent swf, and call a function from parent to the embedded swf. Then, I use the init event for the SWFLoader to invoke the method. Before doing this I have verified that using the same code in a button click handler, it is fine with:
var player:Object = (loader.content as SystemManager).application as Object;
But if in a init event handler, the (loader.content as SystemManager).application is a null.
Whereas, in the document of SWFLoader:
init
Dispatched when the properties and methods of a loaded SWF file are accessible.
I think the problem is here because the application property of your included file is not yet initialized.
You can listen to the APPLICATION_COMPLETE event, which will tell you when the application property of your SWF content is completed.
public var loadedSM:SystemManager;
private function init():void
{
trace("init.");
loadedSM = SystemManager(loader.content);
loadedSM.addEventListener(FlexEvent.APPLICATION_COMPLETE, callFunc);
}
private function callFunc(event:FlexEvent):void
{
LoadFileInclude(loadedSM.application).playVideo();
}
]]>
</mx:Script>
<mx:SWFLoader id="loader" horizontalCenter="0" width="100%" height="362" source="LoadFileInclude.swf" creationComplete="init()" />
I had this same problem. Googling around forever and finally found an answer that led me to the solution buried in this Old Nabble thread.
Basically, when the SWF is injected, the MovieClip itself is in a different place, and it's kind of a pain to get it out. What I did:
MXML:
<mx:SWFLoader
id="loader"
source="#Embed(source='/flash/preloader.swf')" />
AS:
var mc:MovieClip = Loader(DisplayObjectContainer(swf.content).getChildAt(0)).content
as MovieClip;
if(mc)
{
mc.callAFunction();
}

Resources