How to copy something as a pastable bitmap in flash?
So I have simple mxml project - empty page with a panel on it.
I want to be able to select some region on my panel and copy it somehow as bitmap pastable to photoshop, word and other programms.
How to do such thing? (libs, articles etc)
Edit - It may be not possible in FP10 but in FP 10.1 you can have it=)
See BETA ActionScript 3.0 Reference for the Adobe Flash Platform 10.1
Not in the best way ever but any way what's so ever
first use ClipboardFormats -
HTML_FORMAT (which IS supported
by FP10)
Create some template HTML
Embed your BitmapData to it (Use Encoders)
Now you can paste it in to Word and some other programms
You can't do that with Flex/Flash, but you can take a snapshot and save that to the filesystem and import that image to photoshop etc. Here's an example:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.graphics.codec.PNGEncoder;
import flash.display.BitmapData;
protected function saveAsPNG(target:Sprite, path:String):void
{
var bitmapData:BitmapData = new BitmapData(target.width, target.height);
bitmapData.draw(target);
var image:PNGEncoder = new PNGEncoder();
var byteArray:ByteArray = image.encode(bitmapData);
var file:FileReference = new FileReference();
file.save(byteArray, path);
}
]]>
</mx:Script>
<mx:Panel width="100%" height="100%">
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
<mx:Panel width="50%" height="50%"/>
<mx:Panel width="50%" height="50%"/>
</mx:HBox>
</mx:Panel>
<mx:Button label="Save As.." click="saveAsPNG(this, 'MyImage.png')"/>
</mx:Application>
If you use AIR, you can save Bitmaps to the Clipboard. Check out this advanced AIR Clipboard Application.
You also might be able to do the following:
Take snapshot and convert to Base64 encoding
Pass Base64 encoded PNG to Javascript
Save to <img/> tag in HTML
Copy to clipboard
(not sure if that's possible)
It looks like you can't even copy images to the clipboard in javascript. If you're on a Mac, you can use this: Command+Ctrl+Shift+4.
Hope that helps,
Lance
Related
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!
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
I'm using the fxcomponent: Flv video player to play my flv/mob files.
You may get it from here.
Now, player works perfectly as shown in their site, but when I try to use the FXVideo control in popup window (popup manager help is here), the component gives mirror image!, strange, I didn't change any code in that.
So can any one help me out to fix this issue, as I'm novice to action script?
Image:
For quick set up, I'm putting my code here:
FXVideo_Example.mxml file (No change at all except variable)
[Bindable]
private var source:String = "http://localhost/greatcatches.flv";
]]>
</mx:Script>
<controls:FXVideo width="480" height="360" source="{source}" autoPlay="false" bufferTime="10" />
MainPage.mxml:
import mx.core.IFlexDisplayObject;
import mx.managers.PopUpManager;
private function showW():void {
// Create a non-modal TitleWindow container.
var helpWindow:IFlexDisplayObject =
PopUpManager.createPopUp(this, FXVideo_Example, false);
}
]]>
</mx:Script>
<mx:VBox width="480" height="360">
<mx:Button click="showW();" label="Show"/>
</mx:VBox>
Ended up by using spark component!
<s:VideoPlayer id="videoPlayer"
source="http://localhost/greatcatches.flv"
autoRewind="true"
muted="true"
horizontalCenter="0"
verticalCenter="0" />
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>
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>