As a follow up to this question: Developing a online exam application, how do I prevent cheaters?
Can I detect when Flex application looses its focus? that is if a user has clicked onto another application or opened a browser tab?
I read this: Detecting when a Flex application loses focus but was not very clear...
The key part of the code at that link is the
systemManager.stage.addEventListener(Event.DEACTIVATE,deactivate);
The Flash player send outs activate and deactivate events when the focus enters and leaves the player. All you need to do is create a listenr for them and react appropriately.
A more clear example of how to use to the activate and deactivate events can be seen at blog.flexaxamples.com.
Also, it looks like the activate and deactivate events have trouble in some browsers. Colin Moock has more info on that here.
You can add a handler for activate in the main application tag. This detects whenever the flex application comes to focus.
Eg:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
activate="activateHandler(event);"
deactivate="deactivateHandler(event);">
This will work to detect when the Flex windows loses focus, but to detect when the window regains focus without having to actually click on the flex app requires an update in the HTML wrapper, correct? Something like:
<script language="JavaScript" type="text/javascript">
<!--
// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = ${version_major};
// Minor version of Flash required
var requiredMinorVersion = ${version_minor};
// Minor version of Flash required
var requiredRevision = ${version_revision};
// -----------------------------------------------------------------------------
// -->
function onAppFocusIn()
{
${application}.onAppFocusIn();
alert("onAppFocusIn");
}
</script>
<body scroll="no" onFocus="onAppFocusIn()">
I am trying to implement this but the onAppFocusIn() function is not executing once I move back to the flex app window. When I view the source, the code is there. Does anyone know why??
Thanks,
Annie
In Flex 4.6, this command works systemManager.stage.addEventListener(Event.DEACTIVATE, deactivate)
but make sure the flash app wmode is set to window (default). When the wmode was transparent, the event didn't get caught. You set the wmode in the embedded html where you put your flash app. example:
<object classid="clsid:D27WEE-A16D-21cf-90F2-422253540410" width="100%" height="100%"
id="MyApp" name="MyApp" align="middle">
<param name="movie" value="MyApp.swf?v=1.00.008" />
<param name="wmode" value="transparent"> <----- take out this
...
Related
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.
I'm using jquery to drag popup control around the page ,every things work fine but when the page has flash movie the popup doesn't appear over flash also when set z-index to 100 .
is there any work around this issue???
$('.modalPopup').ready(function() {
$('.modalPopup').draggable({ zIndex: 2700 });
});
Add this param to your <object>:
<param name="wmode" value="transparent">
Be aware that there are some issues with this solution (performance, handling hit areas, etc), but this may give you what you need.
Check out this handy demonstration of different WMODEs.
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.
I have a Flash applet which I want to embed in a Flex file this loads a panorama file inside a SWF player (Immervision's PurePlayer)- I am using the following code:
<mx:SWFLoader id="mapLoader"
width="740"
height="588"
source="../bin-debug/PurePlayer.swf?flashvars='panorama=../bin-debug/untitled.ivp'" />
The applet loads fine but it is does not execute the file...
The PurePlayer documentation uses the following var: panorama=myPano.ivp"
If I load the same SWF via a browser window it works fine with the following URL: http://localhost/pureplayer/PurePlayer.swf?panorama=untitled.ivp
Have you tried playing the movie after in your complete handler
// Play it
Object(mapLoader.content).play();
You also might also consider listening for an event once your movie has completed playing or when based user interaction takes place in your Flash app by adding adding an event handler in your Flex application in the complete handler before you play it. You obviously will need to know the type of the event the Flash App is going to dispatch but if bot applications are yours that should be no problem.
mapLoader.content.addEventListener( "yourFlashEvent", handleYourFlashEvent )
You can provide the panorama parameter in the URL to swf file, instead of as a flashvar, like this:
<mx:SWFLoader id="swfLoaderPure"
width="100%" height="100%"
source="../bin-debug/PurePlayer.swf?panorama=myPano.ivp"
complete="onLoadComplete(event)"
/>
i made swf using flash 9 player if i right click swf it will shows menu like zoom in , zoom out, etc option . how to remove right click menu in swf .
check this post: http://blog.another-d-mention.ro/programming/right-click-and-custom-context-menu-in-flash-flex/. If you don't want any interaction with the right click, you can just use that javascript so you add a layer on top of your flash that catches the right click events and stops them from getting to the flash player.
Try this method, or read in this class about what else you can do with the context menu.
i saw ur refer url it's shows Redraw Regions option only .you will changed on your embed code
<param name="MENU" value="false">
The as3 (in movie) put this in first frame :):
myMenu.hideBuiltInItems();
_root.menu = myMenu;
In html:
<EMBED src=Yourswf.swf type="text/html;
charset=iso-8859-1" quality="high" menu=false
bgcolor=#000000 WIDTH=120 HEIGHT=30>