Updating to latest AIR v3.8 causes SWFs loaded from disk to malfunction - air

We have an existing application where, if our users auto-update to Adobe AIR v3.8 it causes interactive SWFs that are loaded from the local disk into an HtmlLoader instance to not function properly. The mouse cursor is stuck in the corner of the window and will not move. I have narrowed the problem down to something in the HTML that we are loading. If the wmode property is changed from "opaque" to "window" the mouse works. If left as shown below wmode="opaque" the mouse cursor will not move.
The SWFs that we are loading in have been coded by various people to varying degrees of quality. In order to protect our application from varying coding practices we 'sandbox' them by using an HTMLLoader instance which loads an HTML file which in turn loads the SWF. This prevents the loaded SWF from walking up to the parent app (our AIR app) and doing unpleasant things like messing with the mouse. This has worked just fine for several years. Now, these SWFs do not work correctly.
Below is the code we are using to set up the HTMLLoader, and below that is the HTML.
`
import core.abstract.ICoreFactory;
import core.abstract.ui.IInteractiveRewardPlayer;
import core.concrete.Instances;
import domain.curriculum.Reward;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.html.HTMLLoader;
import flash.net.URLRequest;
import mx.containers.Canvas;
import mx.containers.VBox;
import mx.core.UIComponent;
import mx.logging.*;
public class InteractiveRewardContainer extends Canvas implements IInteractiveRewardPlayer
{
private static var _logger:ILogger = Log.getLogger("InteractiveRewardContainer");
private var _html:HTMLLoader;
public function InteractiveRewardContainer()
{
super();
}
public function addToDisplay(container:VBox):void
{
container.addChild(this);
}
public function startReward(reward:Reward, width:int, height:int):void
{
_html = new HTMLLoader();
var bitmapHolder:UIComponent = new UIComponent();
var mySprite:Sprite = new Sprite();
var file:String = Instances.coreFactory.resourceLoader.returnHTMLRewardFileName(reward);
_logger.info("File=" + file);
var urlReq:URLRequest = new URLRequest(file);
bitmapHolder.addChild(_html);
_html.width = width;
_html.height = height;
_html.load(urlReq);
mySprite.addChild(_html);
bitmapHolder.addChild(mySprite);
this.addChild(bitmapHolder);
this.width = width;
this.height = height;
}
public function stopReward():void
{
_html.loadString("<html></html>");
}
}
`
and a portion of the HTML. Note the wmode attribute. Changing it to "window" fixes the mouse problem, but then we have a display problem.
<embed src="76381.swf" quality="high" bgcolor="#869ca7" id="RightClickDemo" width="100%" height="100%" name="Bicycle" align="middle" menu="false" play="true" loop="false" quality="high" wmode="opaque" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />
Any ideas what we can do to fix this issue?

Setting wmode to "direct" in the HTML fixed the problem with the mouse, and also maintained the proper display.

Related

Is there a way to apply an alpha mask to a FlxCamera?

I'm trying to implement this camera but one of the obstacles I'm facing right now, is the merging of two cameras (what he describes here).
At first I tried to make a non-rectangular camera, but I don't think it's possible without changing a lot of things in the way HaxeFlixel renders.
And then I found the alphaMask() function in the FlxSpriteUtil package and I think it would be a better solution.
Not only would it solve my problem, it would actually permit all kinds of funky-shaped cameras, you just have to create the right mask!
But the new problem is that I don't know how to (and again, if it's possible without changing a bit the FlxCamera) apply it to the camera.
Internally, the FlxCamera might use a FlxSprite, but only in blit render mode, and I am in tiles render mode (haven't found how to change, not good enough solution in my opinion), which uses a Flash Sprite instead and I don't know what to do with it.
So in short, do you have an idea how to apply an AlphaMask to a FlxCamera? Or another way to achieve what I'm trying to do?
PS: If you want to have a look at the (ugly and frenchly commented) code, it's over here!
You can render the contents of a FlxCamera to a FlxSprite (though it does require conditional code based on the render mode). The TurnBasedRPG tutorial game uses this for the wave effect in the combat screen, see CombatHUD.hx:
if (FlxG.renderBlit)
screenPixels.copyPixels(FlxG.camera.buffer, FlxG.camera.buffer.rect, new Point());
else
screenPixels.draw(FlxG.camera.canvas, new Matrix(1, 0, 0, 1, 0, 0));
Here's a code example that uses this to create a HaxeFlixel-shaped camera:
package;
import flixel.tweens.FlxTween;
import flash.geom.Matrix;
import flixel.FlxCamera;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.graphics.FlxGraphic;
import flixel.system.FlxAssets;
import flixel.util.FlxColor;
import openfl.geom.Point;
using flixel.util.FlxSpriteUtil;
class PlayState extends FlxState
{
static inline var CAMERA_SIZE = 100;
var maskedCamera:FlxCamera;
var cameraSprite:FlxSprite;
var mask:FlxSprite;
override public function create():Void
{
super.create();
maskedCamera = new FlxCamera(0, 0, CAMERA_SIZE, CAMERA_SIZE);
maskedCamera.bgColor = FlxColor.WHITE;
maskedCamera.scroll.x = 50;
FlxG.cameras.add(maskedCamera);
// this is a bit of a hack - we need this camera to be rendered so we can copy the content
// onto the sprite, but we don't want to actually *see* it, so just move it off-screen
maskedCamera.x = FlxG.width;
cameraSprite = new FlxSprite();
cameraSprite.makeGraphic(CAMERA_SIZE, CAMERA_SIZE, FlxColor.WHITE, true);
cameraSprite.x = 50;
cameraSprite.y = 100;
cameraSprite.cameras = [FlxG.camera];
add(cameraSprite);
mask = new FlxSprite(FlxGraphic.fromClass(GraphicLogo));
var redSquare = new FlxSprite(0, 25);
redSquare.makeGraphic(50, 50, FlxColor.RED);
add(redSquare);
FlxTween.tween(redSquare, {x: 150}, 1, {type: FlxTween.PINGPONG});
}
override public function update(elapsed:Float):Void
{
super.update(elapsed);
var pixels = cameraSprite.pixels;
if (FlxG.renderBlit)
pixels.copyPixels(maskedCamera.buffer, maskedCamera.buffer.rect, new Point());
else
pixels.draw(maskedCamera.canvas);
cameraSprite.alphaMaskFlxSprite(mask, cameraSprite);
}
}

Crop PDF & add margins

I have a PDF with a CropBox size of 6" wide x 9" high. I need to add it to a standard letter-sized PDF. If I change the CropBox size, then the cropmarks become visible. So ideally what I'd like to do is crop out just the visible portion of the page, then pad the sides so that the total height and width is letter-sized.
Is this possible using PDFBox or another Java class?
Have you found an answer to your problem ? I have been facing the same scenario this week.
I have a standard letter-size (8,5" x 11") PDF A, containing a header, a footer, and a form. I have no control over that PDF's generation, so the header and footer are a bit dirty and I need to remove them. My first approach was to extract the form into a Box (any type of box works), and then export it as a new PDF page. Problem is, my new Box is a certain size (let's say 6" x 7"), and after thorough research into the docs, I was unable to find a way to embed it into a 8,5" x 11" PDF B ; the output PDF was the same size as my Box. All scenarios either led to a blank PDF file of the right size, or a PDF containing my form but of wrong dimensions.
I then had no choice but to use another approach. It isn't very clean, but hey, when working with PDFs, black magic and workarounds are the main topic. I simply kept the original PDF A, and blanked out all the unwanted parts. That means, I created rectangles, filled them with white, and covered up the sections I wanted to hide. Result is a PDF file, of right dimension, containing only my form. Hooray ! Technically, the header and footer are still present in the page, there was no way to actually remove them ; I was only able to hide them (this doesn't make any difference to the end user as long as you're not hiding sensitive data).
I realize your question was submitted 2 years ago, but I had a very hard time finding a proper answer to my question online, so here's me giving back to the community, and hoping I can help future developers save some time. If you actually found a way to extract a box and embed it in a standard-size page, please post your answer !
Here is my code by the way :
import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.pdmodel.*;
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
import java.awt.Color;
import java.io.*;
import java.util.List;
// This code doesn't actually extract PDF elements per say
// It fills 2 rectangles in white to hide the header and the footer of our PDF page
public class ex {
// Arbitrary values obtained in a very obscure way
static int PAGE_WIDTH = 615;
static int PAGE_HEIGHT = 815;
#SuppressWarnings("unchecked")
public static void main(String[] args) throws IOException, COSVisitorException {
File inputFile = new File("C:\\input.pdf");
File outputFile = new File("C:\\output.pdf");
PDDocument inputDoc = PDDocument.load(inputFile);
PDDocument outputDoc = new PDDocument();
List<PDPage> pages = inputDoc.getDocumentCatalog().getAllPages();
PDPageContentStream pageCS = null;
// Lets paint our pages white !
for (PDPage page : pages) {
pageCS = new PDPageContentStream(inputDoc, page, true, false);
pageCS.setNonStrokingColor(Color.white);
// Top rectangle
pageCS.fillRect(0, 0, PAGE_WIDTH, 30);
// Bottom rectangle
pageCS.fillRect(0, PAGE_HEIGHT-30, PAGE_WIDTH, 30);
pageCS.close();
outputDoc.addPage(page);
}
// Save to file
outputFile.delete();
outputDoc.save(outputFile);
// Wait until the end to close all documents, or else you get an error
inputDoc.close();
outputDoc.close();
}
}
I have adopted the answer of John a little bit, maybe this will help someone.
I have changed the loop to create a new rectangle, with the wanted dimensions. Then the rectangle is set to the page and afterwards added to the new document. I used this snippet to crop a black border out of a long scanned document.
Notice that this will change the size of the pages.
import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class Main {
#SuppressWarnings("unchecked")
public static void main(String[] args) throws IOException, COSVisitorException {
File inputFile = new File("/path/to/your/file");
File outputFile = new File("/path/to/your/file");
PDDocument inputDoc = PDDocument.load(inputFile);
PDDocument outputDoc = new PDDocument();
List<PDPage> pages = inputDoc.getDocumentCatalog().getAllPages();
// Lets paint our pages white !
for (PDPage page : pages) {
PDRectangle rectangle=new PDRectangle();
rectangle.setLowerLeftX(0);
rectangle.setLowerLeftY(0);
rectangle.setUpperRightX(500);
rectangle.setUpperRightY(680);
page.setMediaBox(rectangle);
page.setCropBox(rectangle);
outputDoc.addPage(page);
}
// Save to file
// outputFile.delete();
outputDoc.save(outputFile);
// Wait until the end to close all documents, or else you get an error
inputDoc.close();
outputDoc.close();
}
}
Other than adding a rectangle to the PDPage constructor you can do this do set the CropBox to any size:
PDRectangle box = new PDRectangle(pageWidth, pageHeight);
page.setMediaBox(box); // MediaBox > BleedBox > TrimBox/CropBox

Chart not render correctly when maximizing / restoring window or dragging resize bar (SmartGWT)

I am new to SmartGWT and having this issue for long time and could not fix it.
The charts are not in the right position and not resized after I maximize / restore the window, the same issue exists when I drag the resize bar in the window. However after I drag the edge of the window, even just a little, the charts can be rendered correctly. (looks like there is a delay or something)
I want my charts can render correctly immediately the window is maximized / restored, or when I drag the resize bar. NOT trying to drag the edge of the window every time to correct it.
Please take a look at the below simple case: (I am using HighCharts for charting)
import org.moxieapps.gwt.highcharts.client.Chart;
import org.moxieapps.gwt.highcharts.client.Point;
import org.moxieapps.gwt.highcharts.client.Series;
import org.moxieapps.gwt.highcharts.client.ToolTip;
import org.moxieapps.gwt.highcharts.client.ToolTipData;
import org.moxieapps.gwt.highcharts.client.ToolTipFormatter;
import org.moxieapps.gwt.highcharts.client.labels.PieDataLabels;
import org.moxieapps.gwt.highcharts.client.plotOptions.PiePlotOptions;
import org.moxieapps.gwt.highcharts.client.plotOptions.PlotOptions;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
public class Test1 implements EntryPoint {
public void onModuleLoad() {
Window.enableScrolling(true);
Window.setMargin("0px");
HLayout mainLayout = new HLayout();
mainLayout.setWidth100();
mainLayout.setHeight100();
VLayout vl1 = new VLayout();
vl1.setWidth(250);
vl1.setHeight100();
vl1.setShowResizeBar(true);
VLayout vl2 = new VLayout();
vl2.setWidth100();
vl2.setHeight100();
HLayout top = new HLayout();
HLayout bottom = new HLayout();
VLayout topLeft = new VLayout();
VLayout topRight = new VLayout();
VLayout bottomLeft = new VLayout();
VLayout bottomRight = new VLayout();
topLeft.addMember(drawCharts());
topRight.addMember(drawCharts());
bottomLeft.addMember(drawCharts());
bottomRight.addMember(drawCharts());
top.setMembers(topLeft, topRight);
bottom.setMembers(bottomLeft, bottomRight);
vl2.setMembers(top, bottom);
mainLayout.setMembers(vl1, vl2);
RootPanel.get().add(mainLayout);
}
private Chart drawCharts() {
final Chart chart = new Chart()
.setType(Series.Type.PIE)
.setPlotBackgroundColor((String) null)
.setPlotBorderWidth(null)
.setPlotShadow(false)
.setOption("/chart/marginTop", 0)
.setOption("/chart/marginBottom", 10)
.setPiePlotOptions(
new PiePlotOptions()
.setAllowPointSelect(true)
.setCursor(PlotOptions.Cursor.POINTER)
.setPieDataLabels(
new PieDataLabels().setEnabled(false))
.setShowInLegend(true))
.setToolTip(new ToolTip().setFormatter(new ToolTipFormatter() {
public String format(ToolTipData toolTipData) {
return "<b>" + toolTipData.getPointName() + "</b>: "
+ toolTipData.getYAsDouble() + " %";
}
}));
chart.addSeries(chart
.createSeries()
.setName("Browser share")
.setPoints(
new Point[] {
new Point("Firefox", 45.0),
new Point("IE", 26.8),
new Point("Chrome", 12.8).setSliced(true)
.setSelected(true),
new Point("Safari", 8.5),
new Point("Opera", 6.2),
new Point("Others", 0.7) }));
return chart;
}
}
Do I need to add a resize handler to fix this problem?
Or it may be the problem of the charts layout? I divided the area into four parts (top_left, top_right, bottom_left, bottom_right) and put chart into each part.
Anyone knows how to fix this problem which troubles me a long time? Appreciated.
First of all, I believe your browser share is not very accurate (Lol).
Taking a quick look at your code, it seems that you're mixing GWT charts with SmartGWT, which is not fully supported.
You will have to add some manual handling of the resizes events here.
Take a look at this post :
http://forums.smartclient.com/showthread.php?t=8159#aContainer
and the brief explanation is right here :
http://forums.smartclient.com/showthread.php?t=8159#aMix

How to determine if a dojo grid has finished loading?

I'm working with Selenium to drive a site that uses Dojo. Since the site's Dojo grid uses lazy loading, it's difficult for my test framework to know if/when the grid has finished loading. However, Selenium does let you inject Javascript. Is there a way to either poll the DOM, or use js directly, to find out if a grid has finished loading?
Here is a great answer that I found:
grid.connect(grid, '_onFetchComplete', function(){
for(var i in grid._pending_requests){
if(grid._pending_requests[i]){
return; //no, something's not loaded yet.
}
}
//okay, nothing is on the fly now.
});
http://dojo.6188.n7.nabble.com/function-when-the-dataGrid-is-ready-td37563.html
dojox.grid.DataGrid has an internal flag that gets set in _onFetchComplete, so you could try
var grid = ...
if (grid._isLoaded) {
...
}
I found this question because I was looking for the same thing. The closest I can get is to wait for Dojo's Loading Message to disappear (if the grid loads fast, it's hard to see). Here is what I use right now:
/** Required imports **/
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.By;
/** Code snippet **/
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, /* Max wait time */ 30);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(".dojoxGridLoading"));
This gets me really close.
This is a solution using non-internal event "onStyleRow":
// Declare myGridLoaded
var myGridLoaded = false;
...
...
// Connect onStyleRow:
dojo.connect(grid, "onStyleRow", grid, function(row) {
if(!myGridLoaded) {
doYourStuff();
// Make sure it runs only once:
myGridLoaded = true;
}
});
// Now set your store and the handler will run only once
// when the first row is styled - if any:
grid.setStore(store);

Windowless (not chromeless) Adobe AIR app

What would be the best way to go about building an Adobe AIR app that doesn't have any windows (i.e. exists only in the system tray / dock)? I noticed that the default base tag in Flash Builder is <s:WindowedApplication> which seems to imply there'll be a window.
Should I just use <s:WindowedApplication> and call window.hide()? I saw there's another base class, <s:Application>, but I got the sense that was more for files that run in the browser. It seems like using window.hide() would briefly flash a window when the application starts which could confuse users. However I'd also ideally like to retain the ability to have the app open a window later if needed, or also to change the application from tray-only to windowed through an update.
You need to edit the app-config file to enable transparent chrome and visible = false. Then you need to change the WindowedApplication tag to and app your custom skin. You need to add control buttons for close etc, since that functionality isn't present in a web-app (since you have changed the tag). Also you need to add drag functionality. If you like to make your application re-sizable you need to add that too, manually.
In your manifest (-app.xml) file set systemChrome to none and transparent to true. The visible property is irrelevant, and the default is false anyway so ignore it.
you'll have to tweak this, import whatever classes are missing, etc... you could also do it as an mxml component and just set visible and enabled to false on the root tag. Fill up the trayImages array with the icons you want in the dock.
p
ackage{
import spark.components.WindowedApplication;
public class HiddenApplication extends WindowedApplication{
public function HiddenApplication(){
super();
enabled=false;
visible=false;
var trayImages:Array;
if(NativeApplication.supportsDockIcon||NativeApplication.supportsSystemTrayIcon){
NativeApplication.nativeApplication.activate();
var sep:NativeMenuItem = new NativeMenuItem(null,true);
var exitMenu:NativeMenuItem = new NativeMenuItem('Exit',false);
exitMenu.addEventListener(Event.SELECT,shutdown);
var updateMenu:NativeMenuItem = new NativeMenuItem('Check for Updates',false);
updateMenu.addEventListener(Event.SELECT,upDcheck);
var prefsMenu:NativeMenuItem = new NativeMenuItem('Preferences',false);
prefsMenu.addEventListener(Event.SELECT,Controller.showSettings);
NativeApplication.nativeApplication.icon.addEventListener(ScreenMouseEvent.CLICK,showToolBar);
if(NativeApplication.supportsSystemTrayIcon){
trayIcon = SystemTrayIcon(NativeApplication.nativeApplication.icon);
setTrayIcons();
trayIcon.tooltip = "Some random tooltip text";
trayIcon.menu = new NativeMenu();
trayIcon.menu.addItem(prefsMenu);
trayIcon.menu.addItem(sep);
trayIcon.menu.addItem(updateMenu);
trayIcon.menu.addItem(exitMenu);
}
else{
dockIcon = DockIcon(NativeApplication.nativeApplication.icon);
setTrayIcons();
dockIcon.menu = new NativeMenu();
dockIcon.menu.addItem(prefsMenu);
dockIcon.menu.addItem(sep);
dockIcon.menu.addItem(updateMenu);
dockIcon.menu.addItem(exitMenu);
}
}
function setTrayIcons(n:Number=0):void{
if(showTrayIcon&&(trayIcon||dockIcon)){
Controller.debug('Updating tray icon');
if(NativeApplication.supportsSystemTrayIcon){
trayIcon.bitmaps = trayImages;
}
else if(NativeApplication.supportsDockIcon){
dockIcon.bitmaps = trayImages;
}
}
else if(trayIcon||dockIcon) trayIcon.bitmaps = new Array();
}
}
}