Im using camera class in my mobile application and I used Camera.names to fill my list and i tried to pass the selected value to getcamera() method but its not working.Here s my code
private function init():void
{
if (Camera.names.length == 0) {
lab.text = "No camera attached";
list.enabled = false;
textArea.enabled = false;
}
}
protected function list_changeHandler(event:IndexChangeEvent):void
{
var tList:List = evt.currentTarget as List;
var cameraName:String = tList.selectedIndex.toString();
camera = Camera.getCamera(cameraName);
vid=new Video();
vid.attachCamera(camera);
UIc.addElement(vid as IVisualElement);
textArea.text = ObjectUtil.toString(camera);
}
<s:List id="list"
dataProvider="{Camera.names as ArrayCollection}"
width="200"
change="list_change(event);" />
<s:Group id="UIc" x="68" y="253" width="368" height="281">
</s:Group>
On Android devices, you can only access the rear-facing camera.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Camera.html#getCamera%28%29
When compiling Air for mobile, you need to make sure that your permissions are properly placed in the app xml file. In this case, you need to give your app permission to access the camera for it to work.
Related
I am trying to display remote swf in my flex application, I am able to load swf, but it is not shown(visble) in my flex application.
here is the code
private function onLoaderComplete(event:Event):void{
can.addChild(l);
}
import flash.system.SecurityDomain;
import flash.system.ApplicationDomain;
var l:Loader = new Loader();
private function initApp():void {
var context:LoaderContext = new LoaderContext();
l.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
if(Security.sandboxType == Security.REMOTE){
var context:LoaderContext = new LoaderContext();
context.securityDomain = SecurityDomain.currentDomain;
l.load(new URLRequest('www.somedomain.com/load.swf?id1'), context);
}else{
l.load(new URLRequest('www.somedomain.com/load.swf?id=1'));
}
private function onLoaderComplete(event:Event):void{
can.addChild(l);
}
<mx:Canvas width="100%" height="50%" backgroundColor="red">
<mx:UIComponent id="can" width="100%" height="100%" >
</mx:UIComponent>
</mx:Canvas>
any idea
Thanks all
Your code snippet does not define what 'L' is
The most likely problem you're having with your current code is that you are adding your 'l' onto a UIComponent which has no built in code for sizing and positioning its children, therefore your 'l' will have no height and width, effectively making it invisible.
I would use a SWFLoader to load another SWF File and display it as part of your application.
Rather than deal with trying to figure out the passing of parameters to an embedded SWF, I went ahead and made 20 SWF's all compiled with different values. These SWF's are now inside my Flash Builder application.
There is a state for each SWF (using includeIn) so when the user clicks the button to switch states, the appropriate SWF is displayed.
The problem is that when a user views an SWF, it remains loaded and running in the background. I would like to unload the viewed SWF when the user leaves the state and then load it when it is needed again. If this is not possible, then I will settle for simply reloading the SWF when the state is entered, and just leave the other 19 running in the background.
I have the following:
<fx:Script><![CDATA[
private var flashMovie1:MovieClip;
private var flashMovie2:MovieClip;
private function initFirst():void{
flashMovie1 = dmp_first.content as MovieClip;
}
private function initSecond():void{
flashMovie2 = dmp_second.content as MovieClip;
}
protected function btnFirst_clickHandler():void
{
flashMovie2.Stop();
currentState='First';
flashMovie1.Play();
}
protected function btnSecond_clickHandler():void
{
flashMovie1.Stop();
currentState='Second';
flashMovie2.Play();
}
]]></fx:Script>
<mx:SWFLoader id="dmp_first" includeIn="First" source="assets/images/dmp_first.swf" complete="initFirst()"/>
<mx:SWFLoader id="dmp_second" includeIn="Second" source="assets/images/dmp_second.swf" complete="initSecond()"/>
Along with the above code not working at all with the Stop and Play, I still can't figure out how to force an SWF to reload. Any help would be greatly appreciated!
You can have only one swf at a time using a conatiner. Also you donlt have to use states :) for ex:
<?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"
minWidth = "955"
minHeight = "600">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.controls.SWFLoader;
private function onAppCreationComplete():void
{
showSWF(0);
}
private function onSwfComboChange():void
{
showSWF(cbxSwfData.selectedIndex);
}
private function showSWF(index:int):void
{
grpContainer.removeAllElements();
var swfLoader:SWFLoader = new SWFLoader();
grpContainer.addElement(swfLoader);
swfLoader.load("assets/swfs_files/swf"+index+".swf");
}
]]>
</fx:Script>
<s:ComboBox
id = "cbxSwfData"
dataProvider = "{['swf1','swf2','swf3']}"
change = "onSwfComboChange()"/>
<s:Group
id = "grpContainer"
width = "50%"
height = "50%"/>
</s:Application>
From what I can gather, the resize property of a Flex application is set in the XML config file:
<!--Whether the user can resize the window. Optional. Default true.-->
<!--<resizable></resizable>-->
However, if I set this attribute to true, is there a way to turn this off dynamically at runtime? For example, my application has two view modes - mini and maxi. I would like to prevent the end user from being able to resize the application when in mini mode. I tried prevent the resize using the following code but it does not seem to work:
private function creationComplete():void {
this.systemManager.stage.addEventListener(Event.RESIZE, resizeListener);
}
private function resizeListener(evt:Event):void {
evt.preventDefault();
}
Any help would be greatly appreciated.
There is another way to do that without setting the descriptor file property.
Here is the code:
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" showGripper="false"
layout="vertical" showStatusBar="false"
applicationComplete="init()">
<mx:Script>
<![CDATA[
import mx.events.FlexNativeWindowBoundsEvent;
private function init():void
{
this.stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
nativeWindow.addEventListener(NativeWindowBoundsEvent.RESIZING, onAppResize);
}
private function onAppResize(e:NativeWindowBoundsEvent):void
{
e.preventDefault();
}
]]>
</mx:Script>
Hope this helps.
You'd need to create a new NativeWindow instance and reparent your application into that. When you create a new NativeWindow, you've got options you can set at Initialisation time, including resizable.
http://help.adobe.com/en_US/FlashPlatform//reference/actionscript/3/flash/display/NativeWindowInitOptions.html
According to manual, resizable is read-only property.
So it's probably not possible.
As this was already necro'd, and I was curious:
I was able to implement a switch from resizable to not with the following code:
private var maxMode:Boolean = true;
protected function switchMode():void
{
if (maxMode){
//I chose to freeze the app at current size
//You could also set the min/max to hard coded values
this.maxWidth = this.width;
this.minWidth = this.width;
this.maxHeight = this.height;
this.minHeight = this.height;
}
else {
//default values for WindowedApplication
this.maxWidth = 2880;
this.minWidth = 0;
this.maxHeight = 2880;
this.minHeight = 0;
}
maxMode= !maxMode
}
The user is however still shown the resize mouse icons on the edges of the app.
Try to add return:
evt.preventDefault();
return;
I have a TextInput control which has a search functionality for the people in the system.
It works fine. All I need is to style it in such a way that, it will be having search image on the right, which when clicked, will search. Its actually for look and feel part of the application, which will make the search box look much better.
It is exactly similar behavior implemented in search box embedded in Firefox.
Any solution to this?
Thanks :)
Ack, avoid subclassing. Think outside the Box, as it were, and use a Canvas:
<mx:Canvas>
<mx:TextInput change="doSearchFor(event.currentTarget.text)" />
<mx:Image source="search_icon.png" verticalCenter="0" right="5" />
</mx:Canvas>
Then make that a component itself if you want to make it neater. Favour composition over inheritance, in MXML as elsewhere.
<mx:HBox>
<mx:TextInput id = "txtSearch"/>
<mx:Image source = "yourSearchIcon.png"
click = "doSearch()"
buttonMode = "true"/>
</mx:HBox>
That's all!
You could write a subclass of TextInput Class which has as an image for "yourSearchIcon" image such as:
[Embed(source='../../libs/graphic_elements.swf#search_ico')]
private var searchIcon:Class;
private var searchImg:Image = new Image();
private function onCreationComplete(event:Event) : void {
searchImg.source = searchIcon;
searchImg.x = this.width - 40;
this.addChild(searchImg);
this.addEventListener(ResizeEvent.RESIZE, onResize);
}
obviously you have to handle the resize event
private function onResize(event:ResizeEvent) : void {
searchImg.x = event.currentTarget.width - 40;
}
That's your custom component
Hope this code will help you. This code adds a search icon to the left of the TextInput.
public class SearchInputBox extends TextInput
{
[Embed(source='../../../../assets/images/icons/searchIcon.png')]
private var searchIcon:Class;
private var searchImg:Image;
override protected function createChildren():void
{
super.createChildren();
searchImg = new Image();
searchImg.source = searchIcon;
searchImg.width=15;
searchImg.height=15;
searchImg.x = 2;
searchImg.y = 3;
setStyle("paddingLeft",searchImg.width+2);
addChild(searchImg);
}
}
I'm wondering how to use a VideoDisplay object (defined in MXML) to display video streamed from FMS via a NetStream.
The Flex3 docs suggest this is possible:
The Video Display ... supports progressive download over HTTP, streaming from the Flash Media Server, and streaming from a Camera object.
However, later in the docs all I can see is an attachCamera() method. There doesn't appear to be an attachStream() method like the old Video object has.
It looks like you can play a fixed file served over HTML by using the source property, but I don't see anything about how to attach a NetStream.
The old Video object still seems to exist, though it's not based on UIComponent and doesn't appear to be usable in MXML.
I found this blog post that shows how to do it with a regular Video object, but I'd much prefer to use VideoDisplay (or something else that can be put directly in the MXML).
VideoDisplay is a wrapper on VideoPlayer, which in turn is a Video subclass. Unfortunately, the wrapper prevents you from attaching an existing NetStream to the Video object.
However, a reference to that component is held with in the mx_internal namespace, so the following should do the trick:
videoDisplay.mx_internal::videoPlayer.attachNetStream(incomingStream);
videoDisplay.mx_internal::videoPlayer.visible = true;
(you need to import the mx.core.mx_internal namespace)
Unfortunately you can attachNetStream() only on Video object. So you are doomed to use em if you want to get data from FMS.
By the way attachCamera() method publishes local camera video to the server so be careful ;)
it works.
mx:VideoDisplay live="true" autoPlay="true" source="rtmp://server.com/appname/streamname" />
that will give you live video through a videodisplay... problem is it won't use an existing netconnection object, it creates it's own... which is what I'm trying to find a work around for.
Here a link to example on how to use video:
http://blog.flexexamples.com/2008/03/01/displaying-a-video-in-flex-using-the-netconnection-netstream-and-video-classes/
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
creationComplete="init();">
<mx:Script>
<![CDATA[
import mx.utils.ObjectUtil;
private var nc:NetConnection;
private var ns:NetStream;
private var video:Video;
private var meta:Object;
private function init():void {
var nsClient:Object = {};
nsClient.onMetaData = ns_onMetaData;
nsClient.onCuePoint = ns_onCuePoint;
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");
ns.client = nsClient;
video = new Video();
video.attachNetStream(ns);
uic.addChild(video);
}
private function ns_onMetaData(item:Object):void {
trace("meta");
meta = item;
// Resize Video object to same size as meta data.
video.width = item.width;
video.height = item.height;
// Resize UIComponent to same size as Video object.
uic.width = video.width;
uic.height = video.height;
panel.title = "framerate: " + item.framerate;
panel.visible = true;
trace(ObjectUtil.toString(item));
}
private function ns_onCuePoint(item:Object):void {
trace("cue");
}
]]>
</mx:Script>
<mx:Panel id="panel" visible="false">
<mx:UIComponent id="uic" />
<mx:ControlBar>
<mx:Button label="Play/Pause" click="ns.togglePause();" />
<mx:Button label="Rewind" click="ns.seek(0); ns.pause();" />
</mx:ControlBar>
</mx:Panel>
</mx:Application>
I've seen sample code where something like this works:
// Connect to the video stream in question.
var stream:NetStream = new NetStream( chatNC );
stream.addEventListener( NetStatusEvent.NET_STATUS, handleStreamStatus );
stream.addEventListener( IOErrorEvent.IO_ERROR, handleIOError );
// Build the video player on the UI.
var video:Video = new Video(246, 189);
var uiComp:UIComponent = new UIComponent();
uiComp.addChild( video );
uiComp.width = 246;
uiComp.height = 189;
stream.play( streamName );
video.attachNetStream( stream );
video.smoothing = true;
video.width = 246;
video.height = 189;
view.videoPlayerPanel.removeAllChildren();
view.videoPlayerPanel.addChild( uiComp );
But I can't actually get it to work myself. I'll post here later if I can figure it out.