I'm experimenting with Adobe AIR and Google Maps API in Flex Builder. The question is, i'm making a NativeMenu, and was wondering, how can I change the label of the "Fullscreen" item to "Exit fullscreen" when the stage is in fullscreen?
If you see any thing in the code that could/should be written better, please let me know ;)
Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
height="600"
width="700"
minHeight="100"
minWidth="100"
showStatusBar="false"
title="Gmaps 0.002"
>
<maps:Map
xmlns:maps="com.google.maps.*"
id="map"
mapevent_mapready="onMapReady(event)"
width="100%"
height="100%"
url=""
key=""
/>
<mx:Button id="fullscreenButton" click="toggleFullScreen()"/>
<mx:Script>
<![CDATA[
import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
import com.google.maps.MapMouseEvent;
import com.google.maps.controls.MapTypeControl;
import com.google.maps.controls.ZoomControl;
import com.google.maps.controls.PositionControl;
import flash.display.NativeMenu;
import flash.display.NativeMenuItem;
import flash.events.Event;
import mx.core.Window;
import flash.display.StageDisplayState;
private function onMapReady(event:Event):void {
map.setCenter(new LatLng(59.908165,10.742719), 14, MapType.NORMAL_MAP_TYPE);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
function keyDownHandler(event:KeyboardEvent):void {
if (event.keyCode == 70) {
toggleFullScreen();
}
}
createMenu();
map.enableScrollWheelZoom();
map.enableContinuousZoom();
map.enableControlByKeyboard();
systemManager.stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenHandler);
map.addEventListener(MapMouseEvent.ROLL_OVER, function(event:MapMouseEvent):void {
map.addControl(new ZoomControl());
map.addControl(new PositionControl());
map.addControl(new MapTypeControl());
});
map.addEventListener(MapMouseEvent.ROLL_OUT, function(event:MapMouseEvent):void {
map.removeControl(new ZoomControl());
map.removeControl(new PositionControl());
map.removeControl(new MapTypeControl());
});
}
private function createMenu():void{
var mainMenu:NativeMenu = new NativeMenu();
var fullscreenMenu:NativeMenuItem = new NativeMenuItem("Fullscreen");
var maximizeMenu:NativeMenuItem = new NativeMenuItem("Maximize");
var restoreMenu:NativeMenuItem = new NativeMenuItem("Restore");
var separatorA:NativeMenuItem = new NativeMenuItem("A", true);
var closeMenu:NativeMenuItem = new NativeMenuItem("Close");
fullscreenMenu.addEventListener(Event.SELECT, handleMenuClick);
maximizeMenu.addEventListener(Event.SELECT, handleMenuClick);
restoreMenu.addEventListener(Event.SELECT, handleMenuClick);
closeMenu.addEventListener(Event.SELECT, handleMenuClick);
mainMenu.addItem(fullscreenMenu);
mainMenu.addItem(maximizeMenu);
mainMenu.addItem(restoreMenu);
mainMenu.addItem(separatorA);
mainMenu.addItem(closeMenu);
//fullscreenMenu.enabled = false;
//fullscreenMenu.label = "Test";
this.contextMenu=mainMenu;
}
private function handleMenuClick(e:Event):void{
var menuItem:NativeMenuItem = e.target as NativeMenuItem;
if(menuItem.label == "Fullscreen") toggleFullScreen();
if(menuItem.label == "Maximize") this.maximize();
if(menuItem.label == "Restore") this.restore();
if(menuItem.label == "Close") this.close();
}
private function fullScreenHandler(evt:FullScreenEvent):void {
if (evt.fullScreen) {
//fullscreenMenu.label = "Test";
} else {
}
}
private function toggleFullScreen():void {
try {
switch (systemManager.stage.displayState) {
case StageDisplayState.FULL_SCREEN_INTERACTIVE:
systemManager.stage.displayState = StageDisplayState.NORMAL;
break;
default:
systemManager.stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
break;
}
} catch (err:SecurityError) {
// ignore
}
}
]]>
</mx:Script>
</mx:WindowedApplication>
in order to change a label into a NativeMenu, you can try this
yourNativeMenu.getItemAt(0).label="new_label";
where getItemAt(0) return the first item in the NativeMenu
Related
I am working on Flex 4.6 Air application in which there is a list and the data is transparent background swf file. My problem is that when i double click on the list item the respected swf file should be play in the background or we can say on desktop like virtual girl application. if we minimize the main application, swf should be play on desktop like virtual girl application.
If anybody have any idea please tell me.
Thnank You so much.
You can use the following code in which you will open a mx or spark window on double click of list item.
May be the following code useful for you.
<?xml version="1.0" encoding="utf-8"?>
<s:Window xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:customcomponents="customs.customcomponents.*"
xmlns:services="services.*"
width="100%" height="100%" backgroundAlpha="0"
creationComplete="window1_creationCompleteHandler(event)" minimizable="false"
showStatusBar="false" systemChrome="none" transparent="true">
<fx:Script>
<![CDATA[
import air.net.URLMonitor;
import dbconnection.Connection;
import globalData.DataModel;
import mx.collections.ArrayCollection;
import mx.core.FlexGlobals;
import mx.events.FlexEvent;
import mx.utils.UIDUtil;
import vo.UserSettingsVo;
private var movie:MovieClip;
private var movieTotalFrame:int = 0;
public var countMovie:int = 0;
public var timer:Timer;
private var newRate:int = 0;
private var mainScreen:Screen = Screen.mainScreen;
private var newStyle:CSSStyleDeclaration;
private var flagPreNext:String="";
private var flagFullMin:Boolean = false;
private var monitor:URLMonitor;
private var timerClosePop:Timer;
private var sqlStatStatus:SQLStatement;
private var objSelectedItem:Object;
[Bindable]
private var modellocator:DataModel = DataModel.getInstance();
[Bindable]
private var uservo:UserSettingsVo = UserSettingsVo.getInstance();
private var connection:Connection = Connection.getInstance();
protected function window1_creationCompleteHandler(event:FlexEvent):void
{
seqEffect.target = this;
rotate.target = canDesktopVideo;
loadMovie(0);
}
protected function myVidTeaser_completeHandler(event:Event):void
{
trace(modellocator.arrMovie[countMovie].Videoname.toString());
movie = myVidTeaser.content as MovieClip;
if(movie != null)
{
movieTotalFrame = movie.totalFrames;
var sizeWidth:Number = 0;
var sizeHeight:Number = 0;
/** Always on top setting **/
if(modellocator.userSettingsac[0].alwaysontop == "no")
{
this.alwaysInFront = false;
}
else
{
this.alwaysInFront = true;
}
/** Size Settings **/
if(modellocator.flagMaxMin)
{
sizeWidth = mainScreen.visibleBounds.width;
sizeHeight = mainScreen.visibleBounds.height;
}
else
{
sizeWidth = mainScreen.visibleBounds.width*(modellocator.userSettingsac[0].size/100);
sizeHeight = mainScreen.visibleBounds.height*(modellocator.userSettingsac[0].size/100);
}
if(!this.closed)
{
this.width = mainScreen.visibleBounds.width;
this.height = mainScreen.visibleBounds.height;
}
modellocator.setSizeWidth = sizeWidth;
modellocator.setSizeHeight = sizeHeight;
rotate.autoCenterTransform = true;
rotate.angleYFrom = 0;
myMov.xTo = 0;
myMov.xFrom = mainScreen.visibleBounds.width;
myMov.yFrom = 40;
myMov.yTo = 40;
myMov.duration = 0;
fadeEffect.alphaFrom = 0;
fadeEffect.alphaTo = 1.0;
fadeEffect.duration = 1000;
rotate.play();
seqEffect.play();
}
}
protected function myVidTeaser_enterFrameHandler(event:Event):void
{
if(modellocator.flagDesktopVIdeoPlay == true)
{
if(movie != null)
{
if(movie.currentFrame == movieTotalFrame)
{
if(countMovie == (modellocator.arrMovie.length - 1))
{
countMovie = 0;
}
else
{
countMovie++;
}
/** Show Time Settings **/
movie.gotoAndStop(0);
System.gc();
System.gc();
timer = new Timer(int(modellocator.userSettingsac[0].showtime)*60000);
timer.addEventListener(TimerEvent.TIMER, movieLoadOnTimer, false, 0, true);
timer.start();
}
}
}
else
{
if(timer != null)
{
timer.stop();
timer.removeEventListener(TimerEvent.TIMER, movieLoadOnTimer);
timer = null;
System.gc();
System.gc();
}
event.preventDefault();
event.stopImmediatePropagation();
}
}
private function movieLoadOnTimer(event:TimerEvent):void
{
loadMovie(countMovie);
}
public function loadMovie(num:int):void
{
if(modellocator.arrMovie != null && modellocator.arrMovie.length > 0)
{
if(num < modellocator.arrMovie.length)
{
if(modellocator.arrMovie[countMovie] != null)
{
if(modellocator.arrMovie[countMovie].VideoBuyFlag == "yes")
{
if(flash.system.Capabilities.os.indexOf("Mac") > -1)
{
myVidTeaser.source = "file://" + modellocator.arrMovie[countMovie].VideoFullURL;
}
else
{
myVidTeaser.source = modellocator.arrMovie[countMovie].VideoFullURL;
}
}
else
{
if(flash.system.Capabilities.os.indexOf("Mac") > -1)
{
myVidTeaser.source = "file://" + modellocator.arrMovie[countMovie].VideoTeaserURL;
}
else
{
myVidTeaser.source = modellocator.arrMovie[countMovie].VideoTeaserURL;
}
}
}
}
else
{
countMovie = 0;
loadMovie(countMovie);
}
}
else
{
this.close();
}
}
]]>
</fx:Script>
<fx:Declarations>
<s:Move id="moveUp" duration="500" target="{this}" yFrom="350" yTo="0"/>
<s:Move id="moveDown" duration="500" target="{this}" yFrom="0" yTo="350"/>
<s:Sequence id="seqEffect">
<mx:Move id="myMov"/>
<mx:Fade id="fadeEffect"/>
</s:Sequence>
<s:Rotate3D id="rotate"/>
</fx:Declarations>
<mx:Canvas id="canDesktopVideo" width="100%" height="100%" horizontalScrollPolicy="off"
verticalScrollPolicy="off">
<s:SWFLoader id="myVidTeaser" right="0" bottom="0" width="{modellocator.setSizeWidth}"
height="{modellocator.setSizeHeight}" alpha="{modellocator.setTransparency}"
buttonMode="true"
complete="myVidTeaser_completeHandler(event)"
enterFrame="myVidTeaser_enterFrameHandler(event)" maintainAspectRatio="true"
scaleContent="true"
scrollRect="{new Rectangle(0, 0, myVidTeaser.width, myVidTeaser.height)}"
useHandCursor="true"/>
</mx:Canvas>
</s:Window>
<fx:Script>
<![CDATA[
import mx.controls.*;
import mx.controls.TextInput;
import mx.events.ListEvent;
public function init():void
{
for(var i:int=0;i<5;i++)
{
var txtbox:TextInput = new TextInput();
txtbox.id = "text"+i;
myHBox.addChild(txtbox);
}
}
public function getVal():void
{
}
]]>
</fx:Script>
<mx:HBox id="myHBox" width="100%" height="100%">
<mx:Button label="Get Value" click="getVal()"/>
</mx:HBox>
I have implemented this one. I am getting 5 textboxes with empty value, if i entered some value in each textbox then, i want to get specific 3rd textbox value wen some event trigger. so how i can i make. since am new to flex. Pls give me solutions. Thanks in advance.
Why don't you just store the values in its own data structure?
<fx:Script>
<![CDATA[
import mx.controls.*;
import mx.controls.TextInput;
import mx.events.ListEvent;
private var inputs:Vector.<TextInput> = new Vector.<TextInput>();
public function init():void
{
for(var i:uint = 0; i<5; i++)
{
var txtbox:TextInput = new TextInput();
inputs.push(txtbox);
myHBox.addChild(txtbox);
}
}
public function getVal():void
{
var value:String;
for(var i:uint = 0, len:uint = inputs.length; i<len; i++)
{
value += inputs[i].text + ' ';
}
trace(value);
}
]]>
</fx:Script>
<mx:HBox id="myHBox" width="100%" height="100%">
<mx:Button label="Get Value" click="getVal()"/>
</mx:HBox>
Also, if this is a new project, why are you using Flex 3?
Your question is not all too clear, but if I understand correctly,
Try this:
public function init():void
{
for(var i:int=0;i<5;i++)
{
var txtbox:TextInput = new TextInput();
//txtbox.id = "text"+i;
txtbox.name = "text"+i;
txtbox.addEventListener(Event.CHANGE,onChange);
myHBox.addChild(txtbox);
}
}
private function onChange(event:Event):void{
Alert.show(TextInput(event.target).text,TextInput(event.target).name + " Changed");
}
public function getVal():void
{
Alert.show(TextInput(myHBox.getChildByName("text3")).text,"Value");
}
cheers
In the following code i dont have any error but why is that the addchild(video); i.e, the the video captured by webcam is not displayed
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import org.com.figurew;
import mx.controls.Button;
import mx.controls.Alert;
import flash.display.InteractiveObject;
import flash.display.Sprite;
import flash.media.*;
import flash.net.*;
public function addBody():void
{
var ret:Number = figurew.getInstance().getparam();
if( ret == 1)
{
Alert.show("Camera detected");
}
if(ret == 0)
{
Alert.show("No camera detected");
}
var cam:Camera = Camera.getCamera();
if(cam != null)
{
cam.setMode(640, 480, 30);
var video:Video = new Video(30, 40);
video.attachCamera(cam);
addChild(video);
}
else
{
trace("No Camera Detected");
}
}
]]>
</mx:Script>
<mx:Button label="Test camera" click="addBody();" x="99" y="116"/>
</mx:Application >
figurew.as
package org.com
{
import flash.display.InteractiveObject;
import flash.display.Sprite;
import flash.media.*;
import flash.net.*;
public class figurew extends Sprite
{
public function figurew()
{
//getparam();
var cam:Camera = Camera.getCamera();
if(cam != null)
{
cam.setMode(640, 480, 30);
var video:Video = new Video(300, 450);
video.attachCamera(cam);
addChild(video);
}
else
{
trace("No Camera Detected");
}
}
public function getparam():Number
{
var cam:Camera = Camera.getCamera();
if(cam != null)
{
cam.setMode(640, 480, 30);
var video:Video = new Video(300, 450);
video.attachCamera(cam);
addChild(video);
return 1;
}
else
{
return 0;
trace("No Camera Detected");
}
}
private static var _instance:figurew = null;
public static function getInstance():cldAS
{
if(_instance == null)
{
trace("No instance found");
_instance = new cldAS();
}
return _instance;
}
}
}
I see no place where you set a height or width of the video child of your main application. That may be an issue.
You have an MX Button tag inside the script tag. I suspect this will cause a compilation error. So it is possible that you're viewing an "old" Version of your code. Fix the errors and recompile and relaunch.
I can take snapshot of a component. But the problem is the component is lil bigger with scroll bars. The saved image has scrollbars (only the visible area is getting saved). What i need is I want the entire component to be saved as an image.
This exact functionality is available while we print the component using FlexPrintJob, where by setting the FlexPrintJobScaleType.NONE.
But here in my case i want it to be saved using ImageSnapShot ( not thru FlexPrintJob ).
Thanks Advance,
Sriss
I thought I knew how to do this, but there seem to be lots of awkward issues. I got it working but it's not nice. :-( Maybe you can improve on it.
Here's the code for an example application. And below is the code for the MyCanvas class. When you click the button an image of the Canvas container but without scrollbars should be drawn.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:my="*">
<mx:Script><![CDATA[
import flash.display.BitmapData;
import flash.events.Event;
import mx.containers.Canvas;
import mx.graphics.ImageSnapshot;
import flash.geom.Matrix;
import mx.core.ScrollPolicy;
public function onclick():void
{
var bitmapData:BitmapData = ImageSnapshot.captureBitmapData(canvas);
canvas.addEventListener("BitMapReady", onBitMapReady);
canvas.horizontalScrollPolicy = ScrollPolicy.OFF;
canvas.CreateBitMapData();
}
private function onBitMapReady(e:Event):void
{
DrawBitmapDataAt(canvas.bitMapData, 100, 100);
canvas.removeEventListener("BitMapReady", onBitMapReady);
canvas.horizontalScrollPolicy = ScrollPolicy.AUTO;
}
private function DrawBitmapDataAt(bitmapData:BitmapData,x:int,y:int):void
{
var matrix:Matrix = new Matrix();
matrix.tx = x;
matrix.ty = y;
box.graphics.lineStyle(0,0,0);
box.graphics.beginBitmapFill(bitmapData, matrix, false);
box.graphics.drawRect(x,y,bitmapData.width,bitmapData.height);
}
]]></mx:Script>
<mx:Box id="box">
<my:MyCanvas width="50" height="50" backgroundColor="white" id="canvas">
<mx:Button label="Hello" click="onclick()" />
</my:MyCanvas>
</mx:Box>
</mx:Application>
MyCanvas class:
package
{
import flash.events.Event;
import flash.events.TimerEvent;
import mx.containers.Canvas;
import flash.display.BitmapData;
import mx.core.ScrollPolicy;
import mx.graphics.ImageSnapshot;
import flash.utils.Timer;
public class MyCanvas extends Canvas
{
public var bitMapData:BitmapData;
private var creatingBitMap:Boolean = false;
private var timer:Timer;
public function CreateBitMapData():void
{
this.horizontalScrollPolicy = ScrollPolicy.OFF;
creatingBitMap = true;
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
if (creatingBitMap == true && this.horizontalScrollBar == null)
{
bitMapData = ImageSnapshot.captureBitmapData(this);
this.dispatchEvent(new Event("BitMapReady"));
creatingBitMap = false;
timer = new Timer(10);
timer.addEventListener(TimerEvent.TIMER, onTimer);
this.width += 1;
timer.start();
}
}
private function onTimer(e:TimerEvent):void
{
this.width -= 1;
trace("timer");
timer.removeEventListener(TimerEvent.TIMER, onTimer);
timer.stop();
}
}
}
How do I diable the drag-drop of an image. I've tried to stopPropagation, but that didn't help.
Here is the snippet of the code that I've written
<mx:Image width="24" height="24" complete="init()" dragStart="disableMove(event)"
source="{(data.id==null)?'': (data.id.search('\\.') > 0) ? 'assets/icons/teacher.png' : 'assets/icons/student.png'}"
toolTip="{data.data}" doubleClick="itemDoubleClick(event, data.id)" doubleClickEnabled="true">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import flash.events.MouseEvent;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
private var allCurrentItems: Array = new Array();
private function itemDoubleClick(event: Event, id: String): void {
Alert.show("Clicked = "+id);
}
private function init(): void {
var menuLabel:String = "About School\u00A0";
var cm:ContextMenu = new ContextMenu();
cm.hideBuiltInItems();
var item:ContextMenuItem = new ContextMenuItem(menuLabel);
this.addEventListener(MouseEvent.MOUSE_DOWN, showClick);
//add eventlisteners to the menu item and provide functions
cm.customItems.push(item);
//cm.customItems = [item];
this.contextMenu = cm;
}
private function showClick(event:MouseEvent): void {
if (event.buttonDown) {
Alert.show(String(event.buttonDown));
}
}
private function disableMove(event: MouseEvent): void {
event.stopImmediatePropagation();
}
]]>
</mx:Script>
</mx:Image>
I got it, instead of calling disableMove(event) on dragStart(), I called it on mouseDown() it worked.