Hi All,
I developed an app and I am having the strangest problem where it works fine in windows, but not on the mac/linux platform. It's an image manipulation program where the user loads images into the AIR app from their local file system. Here's the workflow:
- user clicks button that opens file browser
- user selects an image file
- the selected image is loaded onto the stage into a movie clip
- ..other magical things happen to the image
When I use the app in Windows, I can select an image from the file browser and it's added to the stage. When using mac/linux, I can select a file, but it is not added to the stage. Here is code dealing with selecting the image file and loading it onto the stage:
///// START CODE //////
var selectedImage:File = new File();//This holds the location of the file that will be selected using the file browser
controlPanel.select_but.addEventListener(MouseEvent.MOUSE_UP, selectImageFile); //Event listener to open file browser from button press
//This function opens the file browser
functionselectImageFile(e:MouseEvent):void {
var imgFilter:FileFilter = new FileFilter("Images", "*.png;*.jpg;*.bmp"); //Only show image files
selectedImage.browseForOpen("Open", [imgFilter]); //Open file browser
selectedImage.addEventListener(Event.SELECT, fileSelected); //When user selects file, run fileSelected function
}
//This function passes the location of the selected file to the loadimage function
function fileSelected(event:Event):void {
loadImage(selectedImage.nativePath);
}
var imageLoader:Loader; //Create loader object to hold selected image. We are using loader because we need to get properties from the loaded clip that are only accessible on the clip is loaded. loader class allows us to assign event.COMPLETE listener
//Load selected image into loader
function loadImage(url:String):void {
imageLoader = new Loader();//Create new loader
imageLoader.load(new URLRequest(url));//load the selected image
var imageClip:MovieClip = new MovieClip();//Create movie clip to hold the loader
imageClip.addChildAt(imageLoader,0); //Place loader into movie clip. Dont add the movie clip to the stage until the image is loaded
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);//add event listener that tells us when image is loaded
}
//Once image is loaded, add parent clip (imageClip) to stage
functionimageLoaded(e:Event):void {
clipHolder.addChild(e.target.content.parent.parent as MovieClip);
//The reason i am using the event.complete listener is because I need to access properties from the loaded clip that can't be accessed until it's loaded.
}
///// END CODE ////
...As I mentioned earlier, this works perfectly in windows, but not mac/linux. Can anyone offer any insight as to why this may be the case? One theory that I have is that the imageClip is getting cleaned up before it is getting added to the stage via the imageLoaded function. Thanks very much for taking a look!