Question

We're having trouble placing an ad from LeadBolt in the center of the screen in an app built in Adobe Air with ActionScript3.

We are using StageWebView with simple HTML code to surround the script that's used with LeadBolt. The ad loads as it should so no problem there.

The setup we have is that we set the SWF to width=800 and height=480 and we use StageScaleMode.EXACT_FIT and StageAlign.TOP_LEFT. We have tried to set several different values to the rectangle that the viewPort is set to. For instance we have tried with (0, 0, 800, 480) and also 0, 0 and Capabilities.screenResolutionX/Y.

_adWindow.viewPort = new Rectangle(startX,startY,bannerWidth,bannerHeight);

Then we've tried to adjust the placement of the ad itself with css-margin in the HTML sent to loadString(). We've tried to set the margin with _marginLeft both staticly and dynamically (just trying with only marginleft before we go for height as well).

_marginLeft = (Main.screenResX * 0.5) - (1.875 * Main.screensDPI * 0.5);

That's our attempt to try and get a setting for the value of _marginLeft. 1.875 is a value of inches in width, as it seems that the ad always has this static width on all devices. It's supposed to be w:300px but this just doesn't happen?

This is the code we use for our string to call with loadString())

_htmlString = "<!DOCTYPE HTML>";
_htmlString += "<html><body style='margin:0 0 0 " + _marginLeft + "px;padding:0;'>";
_htmlString += "<script type='text/javascript' src='http://ad.leadboltads.net/show_app_ad.js?section_id=xxxxxxx'></script>";
_htmlString += "</body></html>";

It just doesn't work properly. We can get the ad dynamically placed in the middle on a 10.1" tab, but then the ad is placed incorrectly on a 4" phone. The tab has a DPI of 160 (or really 149 from the manufactor, but capabilities shows it incorrectly) and the phone has a DPI of 320 (which is the correct value).

It seems there may be some sort of distortion between pixels in the stagewebview and the values we send into the viewPort? Might it be related to the w:800 and Capabilties.screenResolutionX ratio?

ANY help is appreciated :-)

Was it helpful?

Solution

As suspected it seems to have been the StageScaleMode.EXACT_FIT that screwed things up.

StageScaleMode.NO_SCALE fixes the problem. After that,

adWindow.viewPort = new Rectangle(stage.fullScreenWidth * 0.5 - adWidth * 0.5, 
stage.fullScreenHeight * 0.5 - adHeight * 0.5,
bannerWidth,bannerHeight);

works like a charm :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top