I recently built an AIR app using HTML, CSS and JavaScript. In the web version there is a button on the Capacity tab that opens a new window with the calculated results. After packaging this into an AIR application the app attempts to open the new window but fails.
I read about doing such here, but I am not exactly sure how to implement the code (which follows below).
I would appreciate some guidance to know where this code would go. If there is an "easier" way to accomplish the same results, I am all ears.
Thanks!
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:HTML id="htmlComp" width="100%" height="100%" location="http://www.rediff.com"complete="addEventListenersToLinks(event)" />
<mx:Script>
<![CDATA[
private function addEventListenersToLinks(e:Event):void
{
var dom:Object = e.currentTarget.domWindow.document;
var links:Object = dom.getElementsByTagName("a");
for(var i:Number = 0; i < links.length; i++)
{
if(links[i].target.toLowerCase() == "_blank" || links[i].target.toLowerCase() == "_new")
links[i].onclick = linkClickHandler;
}
}
private function linkClickHandler(o:Object):void
{
navigateToURL(new URLRequest(o.currentTarget.href),"blank");
}
]]>
</mx:Script>
</mx:WindowedApplication>
This was a lot easier than I thought. Basic JavaScript:
CapacityWindow = window.open(document.location, 'CapacityWindow', 'toolbar=1,scrollbars=1,menubar=1,width=800,height=950');
Related
I have a PDF opening in an iFrame using Fancybox. Is it possible to width to screen so in a mobile portrait view, it shows the whole thing, albeit tiny?
I think you can be interested with this example which I Posted September 17, 2015
https://www.autoitscript.com/forum/topic/177368-how-to-get-reference-to-pdf-object-embeded-in-ie/
Firstly you should change size of iFrame Element.
In a second step you should inspect iFrame nad check how PDF object is embeded
For example this could look like this:
<script language="JavaScript">
function rsChange ()
{
var ax = document.all.TestObj;
if ( ax.readyState == 4 )
{
if ( ax.IsInitialized == false )
{
window.setTimeout( "rsChange();", 100 );
}
else
{
ax.Server = "192.168.1.3";
ax.Connect ();
}
}
}
</script>
<OBJECT language='javascript' ID='TestObj' CLASSID='CLSID:36D64AE5-6626-4DDE-A958-2FF1D46D4424' WIDTH='640px' HEIGHT='480px' onreadystatechange='rsChange();'></OBJECT>
<br><br><br>
Don't forget to do a "REGSVR32 UltraVncAx.dll", before viewing this page.<br>
The timer trick in the rsChange() function is required to get the windowful ActiveX initialized properly, before letting the ActiveX create the VNC client child window.
</body>
</html>
In such case you should change parameters in this following object:
<OBJECT language='javascript' ID='TestObj' CLASSID='CLSID:36D64AE5-6626-4DDE-A958-2FF1D46D4424' WIDTH='640px' HEIGHT='480px' onreadystatechange='rsChange();'></OBJECT>
I'm building a AIR application and I need a custom context menu.
My Problem is: There is no context menu in my application!
I searched for long while. Most people want to disable context menu, but I want to enable it. I know how to generate a context menu, but I can't even see the build in context menu.
The reason might be: My swf application cann't capture mouse event.
Anyone know the reason? Thanks very much!
You can implement like this:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="initApp()">
<mx:Script>
<![CDATA[
private function initApp():void {
var ctxMenu:ContextMenu = new ContextMenu();
var clsitem:ContextMenuItem = new ContextMenuItem("Close");
var edititem:ContextMenuItem = new ContextMenuItem("Edit");
var otheritem:ContextMenuItem = new ContextMenuItem("Etc.");
clsitem.addEventListener(Event.SELECT,closeApp);
ctxMenu.customItems.push(clsitem,edititem,otheritem);
this.contextMenu = ctxMenu;
}
private function closeApp(event:Event):void {
this.close();
}
]]>
</mx:Script>
<mx:Panel width="200" height="300">
</mx:Panel>
</mx:WindowedApplication>
I would like to know if its possible to get full screen snapshots from an air application.
What i am interested in, is functionality similar to PrintScreen button in windows, which takes snapshots of all screens, including third party application windows, not just window in which air app is running.
If its not specific to air, and flash/flex API can provide such functionality, it also would be great.
Thanx a lot in advance.
Check out this article as it explains obtaining a screenshot by calling a native process:
import flash.filesystem.File;
import flash.events.NativeProcessExitEvent;
var process:NativeProcess;
if(NativeProcess.isSupported) {
var file:File = File.applicationDirectory;
var args:Vector.<String> = new Vector.<String>();
if (Capabilities.os.toLowerCase().indexOf("win") > -1) {
file = file.resolvePath("PATH/TO/WINDOWS/printscr");
//use your prefered screenshot tool here (e.g. https://code.google.com/p/screenshot-cmd/
//also setup the args as needed
} else if (Capabilities.os.toLowerCase().indexOf("mac") > -1) {
file = file.resolvePath("/usr/sbin/screencapture");
args[0] = "-i";
args[1] = "screencapture.png";
}
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.arguments = args;
nativeProcessStartupInfo.executable = file;
nativeProcessStartupInfo.workingDirectory = File.desktopDirectory;
process = new NativeProcess();
process.start(nativeProcessStartupInfo);
process.addEventListener(NativeProcessExitEvent.EXIT,done);
}else trace("NativeProcess NOT SUPPORTED!");
function done(e:NativeProcessExitEvent):void{
trace("screenshot comprete");
}
One important thing to bear in mind is the AIR device profile.
If you're initially testing in ADL, be sure to use the extendedDesktop profile, otherwise NativeProcess.isSupported will return false.
For more details check out the NativeProcess documentation and the Communicating with native processes in AIR developer guide
I have an air app created from one of Adobe's Examples using javascript / HTML. Is it possible to change the descriptor file so the application launches full screen or maximized?
Or you could call the maximize(); function in the application creation Complete function.
Maybe this helps (from here: http://www.kerkness.ca/how-to-launch-an-adobe-air-windowedapplication-in-full-screen-mode/)
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()">
<mx:Script>
<![CDATA[
private function init():void
{
systemManager.stage.displayState=flash.display.StageDisplayState.FULL_SCREEN_INTERACTIVE
}
]]>
</mx:Script>
</mx:WindowedApplication>
try this one.
onCreationComplete - call this method of the main application creation complete
private function onCreationComplete():void{
var current:Screen;
var scrArray:Array = Screen.screens;
var screens:Array = Screen.getScreensForRectangle(stage.nativeWindow.bounds);
(screens.length > 0) ? current = screens[0] : current = Screen.mainScreen;
this.width = current .bounds.width ;
this.height = current .bounds.height;
this.nativeWindow.x = 0;
this.nativeWindow.y = 0;
}
Is it possible to change the destination of a link based on whether the user has a mac or a PC using javascript?
To give an example: The Apple website allows download of Quicktime but it "knows" whether you are using a mac or a pc and directs you to the relevant page.
Background/Reason for doing this: I have built a website for someone and they have a number of audio and video files on there. Ideally they want it so that if the user is on a mac it will download a quicktime version of the file but if they are on a PC it will download a Windows Media Player file.
Cheers
CHRIS
You can check the UserAgent header to tell Mac and PC browsers apart.
Yes. It's not foolproof, but can be done. Here's a sample of Javascript detecting your OS. You could simply opt to display a different div or something similar depending on the result.
Here is an example
<html>
<head>
<script type="text/javascript">
function yourOS() {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf("win") != -1) {
return "Windows";
} else if (ua.indexOf("mac") != -1) {
return "Macintosh";
} else if (ua.indexOf("linux") != -1) {
return "Linux";
} else if (ua.indexOf("x11") != -1) {
return "Unix";
} else {
return "Computers";
}
}
</script>
<body>
<h1>Welcome to GiantCo Computers</h2>
<h2>We love
<script type="text/javascript">document.write(yourOS())</script>
<noscript>Computers</noscript>
Users!</h2>
</body>
</html>
from http://www.java2s.com/Code/JavaScript/Development/Getusersoperatingsysteminformation.htm