Adding external content to new NativeWindow in Adobe Air

Hi,

I'm working on an Air application that I am building using flash professional CS5.  I have a new native window and am able to add some content (e.g. a text field) to it, but cannot add loaded files.  I have testetd the loader with the default window and its content is added as expected, but using the same method (addChild) with the new native window does not add the loaded content.

I'd appreciate any ideas you may have on how to resolve this.

Best,

C.S.
medxmediaAsked:
Who is Participating?
 
medxmediaConnect With a Mentor Author Commented:
Hi dgofman,

I stumbled onto the answer quite by accident and still don't fully understand it.  When adding a jpg if scaleMode isn't set to "noScale", it doesn't appear. but as soon as it is set to "noScale" it appears.  Here's the code from the test  I was doing, but at this point my question has been answered.

import flash.events.MouseEvent;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.Sprite;

var screenBounds:Rectangle = Screen.mainScreen.bounds;
var screenWidth:Number = screenBounds.width
var screenHeight:Number = screenBounds.height

stage.nativeWindow.x = Math.floor((screenBounds.width - stage.nativeWindow.width)/2);
stage.nativeWindow.y = Math.floor((screenBounds.height - stage.nativeWindow.height)/2);

var AppLoader:Loader = new Loader();
AppLoader.load(new URLRequest("test.jpg"));
AppLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, reportComplete);

var holderMC:MovieClip;

function reportComplete(event:Event) {
      trace("COMPLETE")
      holderMC = new MovieClip;
      //holderMC.addChild(AppLoader.content)
      //addChild(holderMC) // works as does adding AppLoader or AppLoader.content
      openWindow()
}

function openWindow():void {
      var initOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
      initOptions.systemChrome = NativeWindowSystemChrome.NONE;
      var newWindow:NativeWindow = new NativeWindow( initOptions );  
           
      newWindow.width = screenWidth-100;
      newWindow.height = screenHeight-100;
      newWindow.x = 50
      newWindow.y = 50
      
      newWindow.stage.align = "TL";

      newWindow.stage.scaleMode = "noScale"; //if commented out the jpg does not appear

      newWindow.stage.addChild(AppLoader.content);

      newWindow.activate();
}
0
 
dgofmanCommented:
0
 
medxmediaAuthor Commented:
Hi dgofman,

Thanks for your reply.  The link you provided references flash builder.  In Flash, "addElelment" throws an error.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
dgofmanCommented:
Can you attach some sample of your project I would like to run locally on my machine?
0
 
dgofmanCommented:
Ok, now is clear for me.
Yes you have to use code bellow

newWindow.stage.scaleMode = StageScaleMode.NO_SCALE;
newWindow.stage.align = StageAlign.TOP_LEFT;

var bitmap:Bitmap = AppLoader.content as Bitmap;
newWindow.stage.addChild(bitmap);  
newWindow.activate();

for AIR application the NativeWindow class represent as popup window and you cannot apply scaling (like Alert dialogs)
I think  
0
 
dgofmanCommented:
But you can listening resize event and scale your image

http://www.ben-morris.com/howto-add-flex-mx-controls-to-a-nativewindow-for-adobe-air
0
 
dgofmanCommented:
In the precending code, you've also avoided the deformation of the objects on the stage by setting the scaleMode property to StageScaleMode.NO_SCALE.
0
 
medxmediaAuthor Commented:
I stumbled on to my own solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.