Show pdf in Flex air - apache-flex

I went through a document at Adobe Livedocs that describes working with pdf: http://livedocs.adobe.com/flex/3/html/help.html?content=PDF_1.html
But I'm stuck with it and can't get it to work.
Can anyone help me?
thanks
Vladimir

Adobe Air relies on the Adobe Reader browser plugin to render the PDF files. So a user of the AIR application will have to have Adobe Reader installed. This also means that any customization that might have been done by the user to the Adobe Reader interface will be reflected in their AIR app.
This being said, do you have Adobe Reader installed? It has to be at least version 8.1.
You could put a breakpoint in the code below where it checks the pdfCapability and it will tell you whether it supports pdf.
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="onCreationComplete()">
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
public function onCreationComplete():void
{
if(HTMLLoader.pdfCapability == HTMLPDFCapability.STATUS_OK)
{
var htmlLoader:HTMLLoader = new HTMLLoader();
var pdfUrl:URLRequest = new URLRequest("http://www.adobe.com/devnet/flex/pdfs/getting_started_with_Flex3.pdf");
htmlLoader.load(pdfUrl);
htmlLoader.width = 1024;
htmlLoader.height= 768;
pdfComponent.addChild(htmlLoader);
}
}
]]>
</mx:Script>
<mx:VBox>
<mx:Label text="pdf below:" />
<mx:UIComponent id="pdfComponent" />
</mx:VBox>
</mx:WindowedApplication>

Related

How can I import symbols from Flash CS in MXML?

I'm writing a mobile app in Flex with FlashDevelop and using Flash CS6 to create the visual assets. I created a symbol in Flash CS6 and exported it as AC3 into an SWC, which I imported into my FlashDevelop project. I then created a class for it, like so:
package com
{
import flash.display.Sprite;
public class volmeter_class extends Sprite
{
private var design:volmeter;
public function volmeter_class()
{
trace("I'm a MySymbol instance called", name);
design = new volmeter();
addChild(design);
}
}
}
I'm now seeking to display the symbol I created on a page of my app. To do this, I suspect I am expected to somehow import it in my MXML, but I have no idea how to do so. Can someone give me a few tips on how to get started doing this?
In Flash Pro, assure AS Linkage is specified for the symbol.
Using the published SWC from Flash Pro in the ActionScript Build Path of a project, the symbol may be instantiated by AS Linkage. Or, symbols may be embedded from the published SWF of Flash Pro.
Pure ActionScript example:
package
{
import flash.display.Sprite;
public class AppExample extends Sprite
{
public function AppExample()
{
var exampleSymbol:ExampleSymbol = new ExampleSymbol();
addChild(exampleSymbol);
}
}
}
Flex MXML example:
<?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"
creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function creationCompleteHandler(event:FlexEvent):void
{
var exampleSymbol:ExampleSymbol = new ExampleSymbol();
symbol.addChild(exampleSymbol);
}
]]>
</fx:Script>
<s:SpriteVisualElement id="symbol" />
</s:Application>
Another approach would be to embed the symbol by linking a SWF from Flash Pro.
Flex MXML embed example:
<?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">
<fx:Script>
<![CDATA[
[Embed('assets/library.swf', symbol = 'ExampleSymbol')]
[Bindable]
public static var ExampleSymbolClass:Class;
]]>
</fx:Script>
<s:Image source="{ExampleSymbolClass}" />
</s:Application>

Flex 4.6 - Enable onClick (click) on an s:List or s:ArrayCollection

I have been searching thru the posts but I have not been able to find (I could have missed it) how to allow items in an s:List or s:Arraycollection to be clicked to advance to another view in an mobile app. Any help would be much appreciated!
Thanks!
<?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"
creationComplete="onCreationComplete()"
>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
private var _listDataProvider:ArrayCollection = new ArrayCollection(['one', 'two', 'three']);
private function onCreationComplete():void
{
list.dataProvider = _listDataProvider;
list.addEventListener(MouseEvent.CLICK, onListItemClick);
}
private function onListItemClick(event:Event):void
{
Alert.show('Replace this Alert with code to go to view ' + event.currentTarget.selectedItem.toString() + '.', 'Item #' + (event.currentTarget.selectedIndex + 1).toString());
}
]]>
</fx:Script>
<s:List id="list"
horizontalCenter="0"
verticalCenter="0"
/>
</s:Application>
I'm getting the same issue. For some reasons, flash builder is importing the Alert class correctly (import mx.controls.Alert) with its full package name but the project does not compile because it says "Import alert could not be found". I am developing a mobile application using SDK 4.6 which i know doesn't have support for mx controls. This only explains why mx namespace control classes aren't importing properly. I hope this answers your question correctly as i'd advice you to find other means of alerting information to the user. Maybe write a custom alert component or use the platform's alert control via Native extensions.

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 display a fileSystemList list in as3

I am working on an air-application but written in as3.
How can I still display an fileSystemList-Component(flex) written in actionscript?
Thanks
fileSystemList i also Available for AIR Since AIR1.1 see API
also see About file system controls
EDITED Please find AIR APP sample using action script to Create FileSystemDataGrid
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="{onCreationComplet()}">
<mx:Script>
<![CDATA[
import mx.controls.FileSystemDataGrid;
private var fileSystemDataGrid:FileSystemDataGrid;
private function onCreationComplet():void
{
fileSystemDataGrid = new FileSystemDataGrid();
fileSystemDataGrid.directory = File.desktopDirectory.resolvePath('');
fileSystemDataGrid.percentHeight = 100;
fileSystemDataGrid.percentWidth = 100;
this.addChild(fileSystemDataGrid);
}
]]>
</mx:Script>
</mx:WindowedApplication>
Hopes that helps

Programmatically extracting a frame from a video in Flash

I need to write a small Flash app that will need to extract a video frame from a playing video. It will not need to be saved to the HDD of the user. I just need to get the image data and display it in the Flash movie. The frame to extract will be chosen by the user, which is why I'd like to do this purely on the client side (though I know I could do it from the server side).
I've tried searching for solutions but I'm not getting any useful results. Being a Flash newbie I haven't got any code yet seeing as I wouldn't know where to start.
So Flash gurus, is there a way to do this?
If you take a 'screen grab' of a DisplayObject in flash using BitmapData's draw() method.
If you have something for displaying flv somewhere a bit to the right, or down, try something like:
var cloneData:BitmapData = new BitmapData(video.width,video.height,false,0x000000);
cloneData.draw(video);
//test
addChild(new Bitmap(cloneData));
Goodluck!
After reading Georges answer, this is what I came up with as proof of concept. Posting here so it doesn't pollute original question.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="video.load()">
<mx:VideoDisplay id="video" x="0" y="0" source="/content/content.flv" />
<mx:Button x="10" y="10" label="Grab" click="grabClick()"/>
<mx:Button x="71" y="10" label="Play" click="video.play()"/>
<mx:Button x="130" y="10" label="Pause" click="video.pause()"/>
<mx:Script>
<![CDATA[
import mx.controls.*;
import flash.display.BitmapData;
private function grabClick():void {
var bitdata:BitmapData = new BitmapData(video.width, video.height, false, 0x0);
bitdata.draw(video);
var grabResult:Image = new Image();
grabResult.x = 0;
grabResult.y = video.height;
grabResult.source = new Bitmap(bitdata);
addChild(grabResult);
}
]]>
</mx:Script>
</mx:Application>

Resources