Im trying to add minimizable panel in Flex. Is it possible? any ideas guys ?
you can take some idea from the following link:-
http://flexscript.wordpress.com/2008/08/28/flex-minimize-maximize-panel-component/
I digged an old app I had developed in Flex 3. This was how I minimized an Application.
Hope it helps!
private var trayIcon:BitmapData;
//onCreation of App
public function initApp(event:Event):void
{
loadTrayIcon();
this.addEventListener(Event.CLOSING, minToTray);
}
private function minToTray(event:Event):void{
event.preventDefault();
dock();
}
public function loadTrayIcon():void
{
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, readyToTray);
loader.load(new URLRequest("assets/circleblack.PNG"));
}
public function dock():void{
stage.nativeWindow.visible = false;
NativeApplication.nativeApplication.icon.bitmaps = [trayIcon];
}
private function closeApp(event:Event):void{
stage.nativeWindow.close();
}
public function unDock(event:Event):void{
stage.nativeWindow.visible = true;
stage.nativeWindow.orderToFront();
NativeApplication.nativeApplication.icon.bitmaps = [];
}
public function readyToTray(event:Event):void{
trayIcon = event.target.content.bitmapData;
var myMenu:NativeMenu = new NativeMenu();
var openItem:NativeMenuItem = new NativeMenuItem("Open");
var closeItem:NativeMenuItem = new NativeMenuItem("Close");
openItem.addEventListener(Event.SELECT, unDock);
closeItem.addEventListener(Event.SELECT, closeApp);
myMenu.addItem(openItem);
myMenu.addItem(new NativeMenuItem("", true));
myMenu.addItem(closeItem);
this.systemTrayIconMenu
if(NativeApplication.supportsSystemTrayIcon){
SystemTrayIcon(NativeApplication.nativeApplication.icon).tooltip = "Test App";
SystemTrayIcon(NativeApplication.nativeApplication.icon).
addEventListener(MouseEvent.CLICK, unDock);
stage.nativeWindow.addEventListener(
NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGING, winMinimized);
SystemTrayIcon(NativeApplication.nativeApplication.icon).menu = myMenu;
this.nativeApplication.menu = myMenu;
}
}
private function winMinimized(displayStateEvent:NativeWindowDisplayStateEvent):void{
if(displayStateEvent.afterDisplayState == NativeWindowDisplayState.MINIMIZED){
displayStateEvent.preventDefault();
dock();
}
}
Related
I want to have embed video in flash game and have it looped. Is there a way to do it? As my code or more likely .seek or .resume dont give any effect? Am I using wrong commands or?
[Embed(source = "fast.flv", mimeType = "application/octet-stream")]
public var bytes:Class;
public var vidNS:NetStream
public var video:Video = new Video(1280, 720);
public var ns:NetStream;
public function Main() {
Doit();
}
private function Doit():void{
addChild(video);
var vidNC:NetConnection = new NetConnection(); vidNC.connect(null);
vidNS = new NetStream(vidNC);
var metaListener :Object = new Object(); metaListener = { onMetaData: process_Metadata };
vidNS.client = metaListener;
vidNS.addEventListener(NetStatusEvent.NET_STATUS, videoStatusHandler);
vidNS.play(null);
var file:ByteArray = new bytes();
vidNS.appendBytes(file);
video.attachNetStream(vidNS);
}
function process_Metadata (in_Data :Object):void
{
trace("duration is : " + in_Data.duration );
}
function videoStatusHandler (event:NetStatusEvent):void
{
if (event.info.code == "NetStream.Buffer.Empty")
{
trace('loop')
vidNS.seek(0); vidNS.resume();
}
}
You can loop by just simply re-feeding the bytes to the decoder (NetStream)
It's possible that you also need to involve the option RESET_BEGIN:
yourNS.appendBytesAction( NetStreamAppendBytesAction.RESET_BEGIN );
Try setting your code like below:
[Embed(source = "fast.flv", mimeType = "application/octet-stream")]
public var bytes:Class;
public var vidNS:NetStream;
public var video:Video = new Video(1280, 720);
public var ns:NetStream;
//# declare these vars outside of a function for global access
public var file:ByteArray = new bytes();
public var vidNC:NetConnection;
public var metaListener :Object;
public function Main()
{
Doit();
}
private function Doit():void
{
addChild(video);
vidNC = new NetConnection(); vidNC.connect(null);
vidNS = new NetStream(vidNC);
metaListener new Object(); metaListener = { onMetaData: process_Metadata };
vidNS.client = metaListener;
vidNS.addEventListener(NetStatusEvent.NET_STATUS, videoStatusHandler);
vidNS.play(null);
//var file:ByteArray = new bytes();
vidNS.appendBytes(file); //# feed video bytes to decoder
video.attachNetStream(vidNS);
}
function process_Metadata (in_Data :Object):void
{
trace("duration is : " + in_Data.duration );
}
function videoStatusHandler (event:NetStatusEvent):void
{
if (event.info.code == "NetStream.Buffer.Empty")
{
trace('now doing: looping...')
//# there is no timeline ".seek" in appendBytes mode, use ".seek" to clear the buffer for a new re-feed
vidNS.seek(0); //clears the current buffer (video data is removed)
vidNS.appendBytesAction( NetStreamAppendBytesAction.RESET_BEGIN ); //re-set timestamps for decoder
vidNS.appendBytes(file); //re-feed video bytes to decoder
}
}
So Thanks to VC. One i ended up with this code:
[Embed(source="1.flv", mimeType="application/octet-stream")]
public var bytes:Class;
public var vidNS:NetStream;
public var video:Video = new Video(1280, 720);
public var file:ByteArray = new bytes();
public var vidNC:NetConnection;
public var metaListener :Object;
public function Main()
{
Doit();
}
private function Doit():void
{
addChild(video);
vidNC = new NetConnection(); vidNC.connect(null);
vidNS = new NetStream(vidNC);
metaListener new Object(); metaListener = { onMetaData: process_Metadata };
vidNS.client = metaListener;
vidNS.play(null);
vidNS.appendBytes(file);
video.attachNetStream(vidNS);
}
function process_Metadata (in_Data :Object):void
{
trace("loop ");
vidNS.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);
vidNS.appendBytes(file);
}
Its working like it should, but i'm not sure if thats the right way of doing it ^^.
I develop my own way of doing this simple task. However, I'm now wondering if there is a better way to do it.
The buttons:
var menuBtnEscrit:MovieClip = new MovieClip();
var mbe:btnEscritorio = new btnEscritorio();
menuBtnEscrit.addChild(mbe);
menuBtnEscrit.val = "escrit";
menuBtnEscrit.x = 80;
menuBtnEscrit.addEventListener(MouseEvent.CLICK, novoCont);
dMenu.addChild(menuBtnEscrit);
var menuBtnPublic:MovieClip = new MovieClip();
var mbp:btnPublic = new btnPublic();
menuBtnPublic.addChild(mbp);
menuBtnPublic.val = "public";
menuBtnPublic.x = 244;
menuBtnPublic.addEventListener(MouseEvent.CLICK, novoCont);
dMenu.addChild(menuBtnPublic);
And I can keep going, or create buttons trough some algorithm, and put more properties and take advantage of a MovieClip.
The handler:
private function novoCont(e=null){
if(e!=null) selecCont = new String(e.target.parent.val);
clearDisplay(dSubMenu);
clearDisplay(dConteudo);
var func:String = "cont_"+selecCont;
this[func]();
}
As you can see, there is some common task for all buttons.
If I click the first button, it will call cont_escrit() function. This mechanics works, but it is the best practice? Is there a way of optimize it?
public class BaseButton extends Button {
private var _func:Function;
public function get handler():Function {
return _func;
}
public function set handler(value:Function):void {
_func = value;
}
}
So hero you can create mbe like this
mbe = new BaseButton ();
mbe.hanler = cont_escrit;
The event hanler would be
private function novoCont(e=null){
if(e!=null) {
var selecContent:BaseButton = e.targe as BaseButton ;
var handler:Function = selecContent.handler;
handler();
}
}
Here is an example.
var menuBtnEscrit:MovieClip = new MovieClip();
var mbe:btnEscritorio = new btnEscritorio();
menuBtnEscrit.addChild(mbe);
//menuBtnEscrit.val = "escrit";
menuBtnEscrit.func = this.cont_escrit;
menuBtnEscrit.x = 80;
menuBtnEscrit.addEventListener(MouseEvent.CLICK, novoCont);
private function novoCont(e=null){
if(e!=null) {
var mc:MovieClip = e.target as MovieClip;
var func:Function = mc.func;
func();
}
clearDisplay(dSubMenu);
clearDisplay(dConteudo);
}
hope someone can help me with this!
I've written a simple online 3d editor in Flash - it's about to go out to a selection of clients but the file uploader has a bit of a glitch which has only just reared its ugly head. Using FileReference to upload media to https page, it works like a dream on OSX which is what it was built on, but on Windows it's returning Error 2038 on every browser. Has anyone encountered this before?
Any help much appreciated!
public class CustomFileReferenceList extends FileReferenceList {
private var uploadURL:URLRequest;
private var pendingFiles:Array;
public static var length:int = 0;
public static var arrLen:int = 0;
public function CustomFileReferenceList() {
uploadURL = new URLRequest();
uploadURL.url = "https://___";
var rqd:URLVariables = new URLVariables();
uploadURL.method = URLRequestMethod.POST;
rqd.sessionId = Main.sessionId;
uploadURL.data = rqd;
initializeListListeners();
}
private function initializeListListeners():void {
addEventListener(Event.SELECT, selectHandler);
addEventListener(Event.CANCEL, cancelHandler);
}
private function doOnComplete():void {
//var event:Event = new Event(Uploader.LIST_COMPLETE);
//dispatchEvent(event);
enter code here
}
private function addPendingFile(file:FileReference):void {
pendingFiles.push(file);
file.addEventListener(Event.OPEN, openHandler,false,0,true);
file.addEventListener(Event.COMPLETE, completeHandler,false,0,true);
file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler,false,0,true);
file.addEventListener(ProgressEvent.PROGRESS, progressHandler,false,0,true);
file.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler,false,0,true);
file.upload(uploadURL);
}
private function removePendingFile(file:FileReference):void {
for (var i:uint; i < pendingFiles.length; i++) {
if (pendingFiles[i].name == file.name) {
pendingFiles.splice(i, 1);
if (pendingFiles.length == 0) {
doOnComplete();
}
return;
}
}
}
private function selectHandler(event:Event):void {
arrLen = length = fileList.length;
pendingFiles = new Array();
var file:FileReference;
for (var i:uint = 0; i < fileList.length; i++) {
file = FileReference(fileList[i]);
addPendingFile(file);
}
}
private function cancelHandler(event:Event):void {
//var file:FileReference = FileReference(event.target);
}
private function openHandler(event:Event):void {
var file:FileReference = FileReference(event.target);
}
private function progressHandler(event:ProgressEvent):void {
var file:FileReference = FileReference(event.target);
}
private function completeHandler(event:Event):void {
var file:FileReference = FileReference(event.target);
length--;
removePendingFile(file);
}
private function httpErrorHandler(event:Event):void {
var file:FileReference = FileReference(event.target);
}
private function ioErrorHandler(event:Event):void {
var file:FileReference = FileReference(event.target);
}
private function securityErrorHandler(event:Event):void {
var file:FileReference = FileReference(event.target);
}
}
After trying just about every solution, the other web dev found it worked ok minus fancy url names i.e referencing ourserver/thepage.php instead of ourserver/service. Absolutely crazy.
I have today this issue, in my case, I was be trace of the length of the source (url/nativePath) and the length of destin; I was found that the length of the destin url is up to 256 characters.
To solve this, I was be changed the destin point (with simbolic link or network drive)
Example:
// MAC remote path
var mSt:String = "file:////MacBook-Pro-de-Jaime.local/Seagate/netShared/transport-machines/SoftDepot/";
// Windows Remote Drive (\\MacBook-Pro-...\transport-machines)
// Remote MAC as Windows Drive N
var mSt:String = "file:///N:/SoftDepot/";
Voila, the new name reduces several characers.
I have built a OSMF player info my mobile flex application but I can't find a way to tell when the video is done playing. Can I somehow tell when the video is completed?
Thanks in advance!
import mx.core.UIComponent;
import org.osmf.events.TimeEvent;
import spark.components.Button;
import spark.components.Group;
public var playerInstance:StrobeMediaPlayback;
public var grp:Group = new Group();
protected function init(event:Event):void
{
_stage = systemManager.stage;
_stage.align = StageAlign.TOP_LEFT;
_parameters =
{
src:"assets/Mini film 2b with filter on.mp4"
, controlBarMode:"docked"
, controlBarAutoHide: true
, autoPlay: true
, playButtonOverlay:true
, showVideoInfoOverlayOnStartUp: true
};
var playerInstance:StrobeMediaPlayback = new StrobeMediaPlayback();
playerInstance.initialize(_parameters, _stage, systemManager.loaderInfo, null);
playerInstance = playerInstance;
//playerInstance.addEventListener(, remove);
var ui:UIComponent = new UIComponent();
ui.addChild(playerInstance as DisplayObject);
grp.percentWidth = 100;
grp.percentHeight = 100;
addElement(grp);
grp.addElement(ui);
actionBarVisible = false
}
private var urlLoader:URLLoader;
private var urlRequest:URLRequest;
private var loader:Loader;
private var _stage:Stage;
private var _parameters:Object;
/* static */
private static const ALLOW_LOAD_BYTES_CODE_EXECUTION:String = "allowLoadBytesCodeExecution";
public function emptyCache():void
{
//playerInstance.player.pause();
grp.removeAllElements();
this.destructionPolicy = "auto";
}
You can try this:
player.addEventListener(TimeEvent.COMPLETE, onComplete);
function onComplete() {
console.log("Completed");
}
player.addEventListener("complete", onComplete);
API doc
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/org/osmf/events/TimeEvent.html
I can't add name and image from Facebook contacts to SqLite, becouse adding is inside in loop and loader start when Event is Complete. Fllowing code adds data to the database, but in the name of the object is the last person out of the loop. Any thoughts? Thanks!
private var person:PersonVO;
protected function handleFriendsLoad(response:Object, fail:Object):void
{
if (fail) { return }
var friends:Array = response as Array;
var l:uint=friends.length;
for (var i:uint=0;i<l;i++) {
var friend:Object = friends[i];
FacebookDesktop.api('/'+friend.id, loadData);
}
}
private function loadData(object:Object, fail:Object):void
{
if (fail) { return; }
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageToByteArray);
loader.load(new URLRequest(FacebookDesktop.getImageUrl(object.id, 'large')));
person = new PersonVO()
person.name = object.first_name;
}
private function imageToByteArray(event:Event):void
{
var wczytaj:Loader = (event.target as LoaderInfo).loader;
var image:Bitmap = Bitmap(wczytaj.content);
var encoderJpeg:JPEGEncoder = new JPEGEncoder();
var byteArray:ByteArray = encoderJpeg.encode(image.bitmapData);
person.image= byteArray;
insert(person);
}
private function insert(person:PersonVO):void
{
dbStatement.text = "INSERT INTO person (name,image) values(:name,:jpeg)";
dbStatement.parameters[":name"] = person.name;
dbStatement.parameters[":jpeg"] = person.image;
dbStatement.execute();
}
Extend Loader class functionality:
dynamic class DynamicLoader extends Loader{}
Then store whatever you want in instances of DynamicLoader:
private function loadData(object:Object, fail:Object):void
{
if (fail) { return; }
var person:PersonVO = new PersonVO();
person.name = object.first_name;
var loader:DynamicLoader = new DynamicLoader();
loader.person = person;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageToByteArray);
loader.load(new URLRequest(FacebookDesktop.getImageUrl(object.id, 'large')));
}
private function imageToByteArray(event:Event):void
{
var wczytaj:DynamicLoader = (event.target as LoaderInfo).loader as DynamicLoader;
var image:Bitmap = Bitmap(wczytaj.content);
var encoderJpeg:JPEGEncoder = new JPEGEncoder();
var byteArray:ByteArray = encoderJpeg.encode(image.bitmapData);
var person:PersonVO = wczytaj.person;
person.image= byteArray;
insert(person);
}
I have not used private var person:PersonVO;. So if you are not using it in the other methods of your class, you could remove it completely.