How to setup Starling to use full screen iphone4 and iphone5 - actionscript-3

I am considering updating my app to take advantage of iphone5's bigger screen but not sure how to achieve this is as3.
I have tried a few suggestions online however unable to get them working. The app works and looks fine with no modification but just letterboxes top and bottom.
This is my code:
var stageWidth:int = Constants.STAGEWIDTH; // Hardcoded to 320
var stageHeight:int = Constants.STAGEHEIGHT; // Hardcoded to 480
var screenWidth:int = stage.fullScreenWidth;
var screenHeight:int = stage.fullScreenHeight;
Constants.FULLSCREENWIDTH = stage.fullScreenWidth;
Constants.FULLSCREENHEIGHT = stage.fullScreenHeight;
var iOS:Boolean = Capabilities.manufacturer.indexOf("iOS") != -1;
Starling.multitouchEnabled = false;
Starling.handleLostContext = true;
var viewPort:Rectangle = new Rectangle(0, 0, stage.fullScreenWidth, stage.fullScreenHeight);
var startupImage:Sprite = createStartupImage(viewPort, screenWidth > 320);
Many thanks!

Add a launch image named Default-568h#2x.png to the package. The resolution of this launch image should be 1136*640 pixels. In case you are already using a namespace schema for your launch images, you can just append ”-568h#2x” to the namespace schema.
taken from
http://blogs.adobe.com/airodynamics/2012/11/07/deploying-air-apps-on-iphone-5/
also, stageWidth on starling will be 568 now, not 480 like in 3.5" screens
try to hardcode this now.
var screenWidth:int = 640;
var screenHeight:int = 1136;
var viewPort:Rectangle = new Rectangle(0, 0, screenWidth, screenHeight)
starling = new Starling(Game, stage, viewPort);
starling.stage.stageWidth = 320;
starling.stage.stageHeight = 568;
If this works, it means that you get wrong stageWith and stageHeight from stage.stageWidth.
here you can see how to correctly get stageView and stageHeight but that is different topic
http://forums.adobe.com/message/3712344

Related

Adobe AIR Simulator displays wrong size

I'm currently developing a Game via Starling and AS3.
I came across a wierd issue. My Simulator does not display the full stage.
Image for better explanation: http://i.stack.imgur.com/OoMzt.png
I tested around a bit and i found out that a Quad with a 775 height fills the whole height of a 800 stageHeight. Why is it like that? There should be a 25 space.
Is this because i am running on mac and the window displays it wrong?
//////////////////////////////////////////////////
//this is the size used to test NOT the device size
var widthDevelop:int = yourStageWidth;
//Example var widthDevelop:int = 480;
var screenWidth:int = stage.stageWidth;
var screenHeight:int = stage.stageHeight;
var viewPort:Rectangle = RectangleUtil.fit(
new Rectangle(0, 0, widthDevelop, screenHeight*(widthDevelop/screenWidth)),
new Rectangle(0, 0, screenWidth, screenHeight),
ScaleMode.NO_BORDER);
this._starling.viewPort = viewPort;
this._starling.stage.stageWidth = widthDevelop;
this._starling.stage.stageHeight = screenHeight*(widthDevelop/screenWidth);

Loading images using the URLRequest

recently started to learn ActionScript 3 and already have questions.
question remains the same: I'm uploading a picture using the object Loader.load (URLRequest). Loaded and displayed a picture normally. But it is impossible to read the values of attributes of the image height and width, instead issued zero. That is, do this:
var loader:Loader=new Loader();
var urlR:URLRequest=new URLRequest("Image.jpg");
public function main()
{
loader.load(urlR);
var h:Number = loader.height;// here instead of the width of the image of h is set to 0
// And if you do like this:
DrawText(loader.height.toString(10), 50, 50); // Function which draws the text as defined below
// 256 is displayed, as necessary
}
private function DrawText(text:String, x:int, y:int):void
{
var txt:TextField = new TextField();
txt.autoSize = TextFieldAutoSize.LEFT;
txt.background = true;
txt.border = true;
txt.backgroundColor = 0xff000000;
var tFor:TextFormat = new TextFormat();
tFor.font = "Charlemagne Std";
tFor.color = 0xff00ff00;
tFor.size = 20;
txt.x = x;
txt.y = y;
txt.text = text;
txt.setTextFormat(tFor);
addChild(txt);
}
Maybe attribute values must be obtained through the special features, but in the book K.Muka "ActionScript 3 for fash" says that it is necessary to do so. Please help me to solve this. Thanks in advance.
Well it's simple.
Flash is focused on the Internet, hence such problems.
If you wrote loader.load (urlR); it does not mean loaded. Accordingly, prior to the event confirming the end of loading, in loadare Null
if, instead of certain functions would be more code that would perhaps tripped your approach.
Yeah plus still highly dependent on the size of the file that you read.
Well, in general it all lyrics. Listen event on loader.contentLoaderInfo.addEventListener (Event.INIT, _onEvent), onEvent and read properties.
You need to wait for your image to load to be able to get values out of it.
Attach an eventListener to your URLLoader.
var urlR:URLRequest = new URLRequest("Image.jpg");
loader.load(urlR);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
function loader_complete(e:Event): void {
// Here you can get the height and width values etc.
var target_mc:Loader = evt.currentTarget.loader as Loader;
// target_mc.height , target_mc.width
}
Loader

As3 loading blank image

I'm having problems loading an image from an externall source (this was working but we changed the server to a https and made some adjustments).
Now, when I loaded the image, there are no errors, but the width, height are all 0. Also the image is blank.
I tried loading with this script some random internet image and it worked fine. However with the original - (https://www.lovemarks.co/images/be50fe37eac192fb7c0d17353f5ef993a.jpg) - it doesn't work.
var somethingLoaded:Boolean = true;
var actualPic:*;
var pictLdrX:Loader = new Loader();
var pictURLX:String = 'https://www.lovemarks.co/images/be50fe37eac192fb7c0d17353f5ef993a.jpg';
var pictURLReqX:URLRequest = new URLRequest(pictURLX);
var loaderContext:LoaderContext = new LoaderContext();
pictLdrX.load(pictURLReqX);
pictLdrX.contentLoaderInfo.addEventListener(Event.INIT , loadedRemember)
function loadedRemember(event:Event){
var targetLoader:Loader = Loader(event.target.loader);
var newmc:MovieClip = new MovieClip();
addChild(newmc);
newmc.addChild(targetLoader.content);
newmc.x = -targetLoader.width/2;
newmc.y = -targetLoader.height/2;
trace ('w+'+targetLoader.width);
trace ('h+'+targetLoader.height);
trace ('x+'+newmc.x);
trace ('y+'+newmc.y);
}
The way would do it is to first listen for Event.COMPLETE instead of Event.INIT:
pictLdrX.contentLoaderInfo.addEventListener(Event.COMPLETE , loadedRemember);
Then, instead of referencing the actual loader in your handler, just reference the image directly by first casting the Event.target.content as a Bitmap:
function loadedRemember(event:Event)
{
trace("loadedRemember()");
var newmc:Bitmap = Bitmap(event.target.content);
addChild(newmc);
// Your math to center may need to be adjusted
// to account for such a big image size
newmc.x = -newmc.width/2;
newmc.y = -newmc.height/2;
trace ('w+'+newmc.width + '\nh+'+newmc.height + '\nx+'+newmc.x + '\ny+'+newmc.y);
}
Additionally check for any security errors related to cross domain within your output window.

AS3 Multiple Webcams not showing 3rd webcam

Hi I'm trying to create a simple AIR 3 application that displays 3 Webcams on the stage. For some reason the 3rd webcam doesn't want to show, it doesn't even turn on the LED indicator on the webcam.
I have tried multiple webcams eg. microsoft, logitech, built in....
The following code doesn't work:
var videoWidth:int = 1000 / totalCols;
var videoHeight:int = 800 / totalRows;
for (var i:int = 0; i < Math.min(Camera.names.length, totalRows * totalCols); i++) {
var currRow:int = Math.floor(i / totalCols);
var currCol:int = i % totalCols;
var video:Video = new Video(videoWidth, videoHeight);
var cam:Camera = Camera.getCamera(i.toString());
if (cam) {
cam.setMode(videoWidth, videoHeight, 30);
video.attachCamera(cam);
video.x = currCol * videoWidth;
video.y = currRow * videoHeight;
StageObj.addChild(video);
}
}
Neither does this:
//camera settings
track_cam = new Camera();
track_cam = Camera.getCamera("1");
track_cam.setMotionLevel(100);
track_cam.setQuality(0, 100);
track_cam.setMode(1920, 1080, 30);
track_feed = new Video();
track_feed.width = track_cam.width;
track_feed.height = track_cam.height;
track_feed.smoothing = true;
track_feed.attachCamera(track_cam);
StageObj.addChild(track_feed);
player_one_cam = new Camera();
player_one_cam = Camera.getCamera("2");
player_one_cam.setMotionLevel(100);
player_one_cam.setQuality(0, 100);
player_one_cam.setMode(200, 200, 30);
player_one_feed = new Video();
player_one_feed.width = player_one_cam.width;
player_one_feed.height = player_one_cam.height;
player_one_feed.smoothing = true;
player_one_feed.attachCamera(player_one_cam);
StageObj.addChild(player_one_feed);
player_one_feed.x = 500;
player_one_feed.y = 500;
player_two_cam = new Camera();
player_two_cam = Camera.getCamera("0");
player_two_cam.setMotionLevel(100);
player_two_cam.setQuality(0, 100);
player_two_cam.setMode(200, 200, 30);
player_two_feed = new Video();
player_two_feed.width = player_two_cam.width;
player_two_feed.height = player_two_cam.height;
player_two_feed.smoothing = true;
player_two_feed.attachCamera(player_two_cam);
StageObj.addChild(player_two_feed);
Is there a limit on the amount of webcams you can use in AS3?
It seems that I ran out of USB Bandwidth, when using usb 3 on a seperate machine it started working.
Looks like it should work from the docs:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Camera.html#getCamera()
name:String (default = null) — Specifies which camera to get, as
determined from the array returned by the names property. For most
applications, get the default camera by omitting this parameter. To
specify a value for this parameter, use the string representation of
the zero-based index position within the Camera.names array. For
example, to specify the third camera in the array, use
Camera.getCamera("2").

AS3 webcam resolution/size issue

I do not really know much in regard to Flash or Action Scripts but I have been having a bit of trouble with AS3 and webcams. I have a script that connects to a webcam and then sends its output to a php script that saves the captured image. This works all except for one problem. It seems that the maximum resolution allowed for the actual Camera object is 320x240. I went to the extreme of hooking a Canon 60D up as a webcam because I have a normal webcam that is supposed to have max resolution of 1280x720 and all I can get is a 320x240 image from it. What I have found so far is the max I can get out of the Canon is also 320x240. Maybe I have been looking at this to long but I am stumped. Below is a sample of the action script where videoCapture should be 1024x768. What happens instead is a 1024x768 image is created with a black background and in the top left is a 320x240 image from videoCapture. I could obviously resize this but that would defeat the purpose being poor quality. Is there something I am missing here or maybe some limitation of Flash even?
// adds event listener to the stage for keydown events.
stage.addEventListener(KeyboardEvent.KEY_DOWN, detectEnterKey);
import flash.display.Bitmap;
import flash.display.BitmapData;
import com.adobe.images.JPGEncoder;
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
var bandwidth:int = 0;
var quality:int = 100;
var cam:Camera = Camera.getCamera();
var videoCapture:Video = new Video();
var previewPortData:BitmapData = new BitmapData(1024, 768, true, 0x00000000);
var previewPort:Bitmap = new Bitmap(previewPortData);
function onCameraStatus(evt):void {
if (evt.code == "Camera.Muted") {
Security.showSettings(SecurityPanel.CAMERA);
}
}
// detects the keycode looking for enter key pressed.
function detectEnterKey(event:KeyboardEvent):void {
//trace("keycode: "+event.keyCode);
if (event.keyCode == Keyboard.ENTER) {
previewPortData.draw(videoCapture);
var myEncoder:JPGEncoder = new JPGEncoder(100);
var byteArray:ByteArray = myEncoder.encode(previewPortData);
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var saveJPG:URLRequest = new URLRequest("save.php");
saveJPG.requestHeaders.push(header);
saveJPG.method = URLRequestMethod.POST;
saveJPG.data = byteArray;
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, sendComplete);
urlLoader.load(saveJPG);
function sendComplete(event:Event):void {
trace("compete");
}
}
}
if (cam == null) {
Security.showSettings(SecurityPanel.CAMERA);
} else {
cam.addEventListener(StatusEvent.STATUS, onCameraStatus)
cam.setQuality(bandwidth, quality);
cam.setMode(1024, 768, 30, false);
videoCapture.attachCamera(cam);
videoCapture.width = 1024;
videoCapture.height = 768;
addChild(videoCapture);
previewPort.x = 430;
previewPort.y = 50;
addChild(previewPort);
}
I also just had this problem. Solved it by including the width and height parameters when creating the Video object instead of setting them afterwards via Video.height and Video.width. Once i did that, all bitmapData taken from that video was correctly sized.
This is how i originally created the video that did not work (looked fine, but resulted in incorrectly sized bitmaps):
var vid = new Video();
vid.width = 640;
vid.height = 480;
...
This worked (bitmaps from this video were correctly sized):
var vid = new Video(640, 480);
...
Would love to know why the first way doesn't work. Maybe that's the bug mentioned above. (I didn't have access to that site so couldn't see it.)
Sounds like this bug was never fixed: http://bugs.adobe.com/jira/browse/FP-2138
I had a similar issue. What worked for me was that I replaced:
previewPortData.draw(videoCapture);
With:
previewPortData.draw(stage);