Make Flex mobile full screen in desktop (as an air app) - apache-flex

I need to make flex mobile application to be full screen when it runs on desktop OSs (I've packaged it as an air app)

I'm pretty sure that your view will dispatch it's creationComplete event before the main Application is added to the stage, which is probably why you got the error.
In the past, I've used the applicationComplete event and the StageDisplayState.FULL_SCREEN. Here is an old blog post I wrote about it.
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" alwaysInFront="true"
applicationComplete="onApplicationComplete()">
<mx:Script><![CDATA[
public function onApplicationComplete():void{
this.stage.displayState = StageDisplayState.FULL_SCREEN;
}
]]></mx:Script>
</mx:WindowedApplication>
I see no reason why this code wouldn't work in a Flex 4 / Spark app.

Switching to full screen through stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE can not be done on a creation complete handler. It must be done through user interaction. I actually just did this yesterday. Add a button to your app and set the onClick to a function that sets full screen and hides the button. That's how I did it anyways.

Related

flex browser application initialization

Would anyone be able to point out some good tutorials on creating applications in flex that are don't have UI's?
Actually, it looks like all I really need to know is how to call a function upon initialization of the flash object. I tried the creationComplete attribute, but it doesn't work in browser.
Well, I'm not sure what made it work finally, but I ended up copying and pasting this code from some website (sorry, i don't remember the site):
<?xml version="1.0" encoding="utf-8"?>
<!-- wrapper/CheckExternalInterface.mxml -->
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark"
creationComplete="initApp()">
</s:Application>
And that ended up working! thanks anyway.
If you're intent is to connect JavaScript to a Java Server, why not use XMLHTTPRequest? IT is the basis of every AJAX style RIA application. The data format you pass back and forth can either be JSON or XML. It doesn't have to be binary.
Second, you don't need Flex for this. The Sockets APIs in ActionScript and are part of the Flash Player. You can use them without any dependencies to the Flex Framework.

Adword: Encountered flash error - ad cannot use mouse tracking

Trying to create a banner ad as a one-off project for a client. I am using Flash Builder / AS 3 and with my simple hello world example. Google Adwords rejects the add with: Encountered flash error - ad cannot use mouse tracking.
I Have not been able to figure out what I am doing that signals to Adwords that I am mouse tracking. Follows is my simple mxml file: (the handleClick is to adhear to their clickTAG specification)
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" minWidth="336" minHeight="280" width="336" height="280" includeInLayout="true" click="handleClick(event)">
<fx:Script>
<![CDATA[
public function handleClick(mouseEvent:MouseEvent):void {
navigateToURL(new URLRequest(root.loaderInfo.parameters.clickTAG),"_blank");
}
]]>
</fx:Script>
</s:Application>
It is quite possible that whatever automated analysis that Google does on the ads submitted is being confused by the Flex framework. You could try creating an ActionScript project instead of Flex project in Flash builder and see if that makes any difference.
If you use an ActionScript project you won't be able to use MXML for creating the ad, but you might not really even want to drag in the Flex framework, since it takes a while to load (the first time at least).

AIR: Security Sandbox Violation when using remote images

The code below is simplified for example
I'm developing an AIR application (using Flex) which loads several of its images from a remote web server. The images display fine, however, whenever I'm manipulating the containers which hold the remotely-loaded images, I get errors in my console:
*** Security Sandbox Violation ***
SecurityDomain 'http://www.google.com/intl/en_ALL/images/logo.gif' tried to access incompatible context 'app:/sandbox_test.swf'
The images don't seem to be affected, but I don't like having errors displayed that I don't understand. Here's a sample app that exemplifies the problem:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication width="500" height="500" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:HDividedBox width="100%" height="300" horizontalCenter="0" verticalCenter="0" backgroundColor="#000000" liveDragging="true">
<mx:Image source="http://sstatic.net/so/img/logo.png"/>
<mx:Image source="http://www.google.com/intl/en_ALL/images/logo.gif"/>
</mx:HDividedBox>
</mx:WindowedApplication>
If you drag using the dragger on the HDividedBox, the security error appears.
I've looked at some of the Security class / security sandbox stuff for AIR, but by default AIR should have access to networked resources (which is why the images load I think). Using Security.allowDomain("www.google.com") isn't an option in AIR - it just throws a SecurityError.
Does anyone know what's causing it, or how to fix it? (Or maybe it's just a Flex/AIR bug?).
Also - does anyone know if there's a way to break when the error happens, so I can trace it to the root action causing it?
This security sandbox issue is specific to dragging UIComponents that have Image components in them. The Image components reference external images. I've looked everywhere and every post I run into the thread ends unanswered, which typically means its a bug.
My bootleg workaround? After the image has downloaded to the Image component, cache it as a bitmap and reassign the Image components source to the Bitmap. This fixed the issue for me:
private function authorImageLoadComplete(event:Event):void {
var bp:Bitmap = dupeImage(authorImage);
authorImage.source=bp;
}
private function dupeImage(source:Image):Bitmap {
var data:BitmapData = Bitmap(source.content).bitmapData;
var bitmap:Bitmap = new Bitmap(data);
return bitmap;
}
Then your image tag in your UIComponent:
<mx:Image id="authorImage" complete="authorImageLoadComplete(event)"></mx:Image>
Best of luck guys
For Flex 4, try setting the top level WindowedApplication's useNativeDragManager property to false, as documented here: http://cookbooks.adobe.com/post_How_do_you_make_a_Spark_custom_itemRenderer_with_a-16532.html
Do this images show up when you aren't running in Debug? The problem is that the domain doesn't have a crossdomain.xml file setup to allow for images in Flash.
http://www.google.com/crossdomain.xml:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="by-content-type" />
</cross-domain-policy>
You should probably just grab the images and place them in your application's assets, or on a domain you control and can properly add a crossdomain.xml that would allow for the content. Security.allowDomain isn't going to have the affect you are looking for. This article has the best explanation of crossdomain security I have read.
See ryanstewart's comment below. The above is hogwash for an AIR app.

Flash and Flex

I want to embed a Flash movie into Flex (Flex Builder 3), both using Action Script 3, and have my flash movie call functions in Flex and vice versa.
Is this possible?
Yes it is possible. If you want to embed another swf into your flex application you have a few options.
Option 1 - Embed the swf, inline, into a SWFLoader component. This option has some security drawbacks as the swf gets loaded into another application domain and so communication between your flex app and the embedded content can sometimes be difficult. You can give this component an id, listen to the complete event and then talk to the content property of SWFLoader to get access to the loaded swf. Something like:
<mx:Script>
<![CDATA[
private function completeHandler(event : FlexEvent) : void
{
trace(mySwfLoader.content);
}
]]>
</mx:Script>
<mx:SWFLoader id="mySwfLoader" source="#Embed(source='YourSwf.swf') complete='completeHandler(event)" />
Option 2 - You could use a meta tag to embed the swf as a class and then create an instance of that class in code. This is gives a lot of flexibility but you loose the benefits of being able to add the object declaratively. Something like:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="creationCompleteHandler(event)">
<mx:Script>
<![CDATA[
[Embed(source="mySourceSwf.swf")]
private var mySourceSwfClass : Class
private function creationCompleteHandler(event : FlexEvent) : void
{
var mySourceSwf = new mySourceSwfClass();
myCanvas.addChild(mySourceSwf);
trace(mySourceSwf);
}
]]>
</mx:Script>
<mx:Canvas id="myCanvas" />
</mx:Application>
Option 3 - Don't have a swf at all. Have whatever you want to embed as a UIMovieClip in the fla. You can then create a .swc file whenever you publish that fla. You can then link to that swc file in flex builder. this will then automatically add that MovieClip as referencable in your project (this may need some more investigation on your part). Essentially you can then do something like:
<local:MyMovieClipInSwc id="myMovieClip" />
This way you get the benefits of both worlds, declarative markup and everything within the same application domain. One thing i would say about this method is that Adobe royally f**ked up with the UIMovieClip class and it's performance sucks. Just be aware if you start to use this everywhere you app may become extremely sluggish.

In AIR how to set focus on textinput on application load?

On my application I have a login form. On application start, I want the focus/selected one is set on the user id textinput.
I tried normal setFocus method and didnt worked.
How can i make it work?
This works for me with Flex 3 and AIR 1.5:
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:applicationComplete>
ti.setFocus();
</mx:applicationComplete>
<mx:TextInput id="ti"/>
</mx:WindowedApplication>

Resources