12-15-2010 08:08 PM - edited 12-15-2010 08:49 PM
I found something weird about qnx.ui.display.Image setSize. I have an Image object does not display the enlarging size that I set during constructor, but instead display in actual image resolution. But it did display well with enlarging size during mouse event function. I really have no idea what's going on... Thanks in advance for help ![]()
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import qnx.ui.display.Image;
[SWF(width="1024", height="600", backgroundColor="#cccccc", frameRate="30")]
public class AIRHelloWorld extends Sprite
{
private var image1:Image;
public function AIRHelloWorld()
{
image1 = new Image;
image1.setImage('assets/abc.png'); // image resolution 57 x 57
image1.setPosition(200, 10);
image1.setSize(77, 77); // it does NOT display 77 x 77 size, but 57 x 57 instead
image1.addEventListener(MouseEvent.MOUSE_DOWN, downWindow);
image1.addEventListener(MouseEvent.MOUSE_UP, upWindow);
addChild(image1);
stage.nativeWindow.visible = true;
}
private function downWindow(event:MouseEvent):void{
image1.setPosition(200 - 10,10 - 10);
image1.setSize(77,77); // it did display 77 x 77 well here...
}
private function upWindow(event:MouseEvent):void{
image1.setPosition(200,10);
image1.setSize(57,57);
}
}
}
Solved! Go to Solution.
12-15-2010 08:13 PM
Try setting the size after being added to the display list (after addChild()).
12-15-2010 08:52 PM
Thanks for reply, John! I have tried to set the size after addChild() and stage.nativeWindow.visible = true, but no clue. Any other suggestion? Thanks!
12-15-2010 10:06 PM
hey,
so i found that when you first declare the image and add it to the parent object its just instructions telling it what to do. however, you are giving instructions to an empty object. It's like that rule where a sprite has no dimension of width or height unless you add children to it. so this applies to this case as well. until the image is loaded setting it's width and height does nothing because it has no "children" in the object. once the image is loaded by the application it finally has dimension and can be modified. so what i recommend is attaching an event listener to listen for when the image is loaded like below:
var myImage:Image;
(...)
myImage = new Image();
myImage.addEventListener(Event.COMPLETE, onLoad);
myImage.setImage("images/ball.png");
myImage.setPosition(600,300); //dont mind this just random
addChild(myImage);
(...)
public function onLoad(e:Event):void
{
var myImageObject:Image = (e.target as Image);
myImageObject.setSize(myImageObject.width*2,myImag eObject.height*2);
}
to us its loaded instantly but to the runtime its not yet loaded so nothing can be done to it before its loaded. so once its loaded you should be able to manipulate it how you like. hope that helps! good luck!
12-15-2010 10:26 PM
Thanks, it works great!
12-16-2010 12:00 AM
This is a race condition since the result depends on what completes first - the layout thread or the image loading thread.
I suspect you're going to need some form of memory barrier that resizes the image when both the image and sizing data are available.
Useful links
1. http://stackoverflow.com/questions/3047099/why-doe