Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

graphics drawing function success?

Has anyone had success in using the graphics drawing routines (beginFill, drawRect, endFill, moveTo, lineTo, etc) under the QNX Sprite or QNX UIComponent?  I can some very odd behavior, most notibly, scaling.  I try to draw a rect a certain size, it it does not draw it that size.  It works fine under the MX/AIR application.  I still need to try it under MX/WindowApplication method to verify I am not going nuts.  Just wanted to check in to the group to see if anyone else had success with just drawing something simple.

 

Also, the QNX containers dont have updateDisplayList and invalidateDisplayList like functionality, so how do these containers get refreshed on a change in size or other?

Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: graphics drawing function success?

hey jtegen,

 

i've used the shape class and its graphics functions and they seem to work fine.. only bump i ran into was when i initially set the x and y values using the drawRect function it doesnt store the values to the object.x or object.y for some reason... the workaround for that was set it manually so i can access the values later.

 

do you have a snippet of the code giving you a problem?

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: graphics drawing function success?

I will try to isolate the issue and post the code early next week (gone all weekend).  I will try the shape class too to see if that is any different.  Problem is that I have been using MX library for so many years, you get kind of use to how it works and all the heavy lifting it does for you without question.  Feel like I have to re-learn a bunch of stuff that worked fine under the MX library.

Developer
shawnblais
Posts: 439
Registered: ‎10-25-2010
My Device: Not Specified

Re: graphics drawing function success?

There's no "QNX" Sprite class, just your regular AS3 Sprite. Drawing seems to work fine there, not sure about UIComponent.

Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: graphics drawing function success?

[ Edited ]

Very interesting.  Seems to have to do when I size (specify the width and height) of a child Sprite class, the drawing function is ignore (or not seen), removing the width and height specification allows the child sprite to be drawn.

 

Here is main class:

SWF(height="600", width="1024", frameRate="30", backgroundColor="#000000")]
public class LayoutExample3 extends Sprite
{
	private var box :Sample3Box = new Sample3Box();
		
	///////////////////////////////////////////////////////////////
	public function LayoutExample3()
	{
		super();
		stage.nativeWindow.visible = true;
		this.draw();
			
		box.x = 200;
		box.y = 0;
			
		this.addChild( box );
		//box.width = 100;
		//box.height = 100;
		box.draw();
	}
		
	////////////////////////////////////////////////////////////////
	private function draw() : void
	{
			this.graphics.clear();
			this.graphics.lineStyle(2, 0xFFFFFF, 1 );
			this.graphics.drawRect( 10, 10, 100, 100 );
			this.graphics.endFill();
	}
}

 Code for child Sprite:

import flash.display.Sprite;
	
public class Sample3Box extends Sprite
{
	//////////////////////////////////////////////////////////
	public function Sample3Box()
	{
		super();
		this.width = 100;
		this.height = 100;
	}
		
	////////////////////////////////////////////////////////////
	public function draw() : void
	{
	  this.graphics.clear();
	  this.graphics.lineStyle(2, 0xFFFFFF, 1 );
	  this.graphics.drawRect( 0, 0, this.width, this.height );
	  this.graphics.endFill();
	}
}

 

I will need to check my other MX applications, but I could swear that I commonly size the sprite to allow the drawing to reference is overall size.  Am I nuts?

 

Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: graphics drawing function success?

hey jtegen,

 

a couple of things i noticed:

 

If you add content to the sprite everything works fine... then i went and looked at the Sprite API and looked at the width property and found this:

 

 

Except for TextField and Video objects, a display object with no content (such as an empty sprite) has a width of 0, even if you try to set width to a different value.

 

here's the link: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#...

 

so apparently even if you set the width of a sprite object manually through its property and it doesnt change the value and it remains a 0 until u add a child object to it. only then does ur width property changes go into effect. i tested this out and it it works well:

 

 

package
{
import flash.display.Sprite;
import flash.text.TextField;

public class Sample3Box extends Sprite
{
//////////////////////////////////////////////////////////
public function Sample3Box()
{
super();

var textField:TextField = new TextField();
textField.text = "Here is some content";

this.addChild(textField);

this.width = 100;
this.height = 100;
}

////////////////////////////////////////////////////////////
public function draw() : void
{
this.graphics.clear();
this.graphics.lineStyle(2, 0xFFFFFF, 1 );
this.graphics.beginFill(0xFF0000, 1);
this.graphics.drawRect( 0, 0, this.width, this.height );
this.graphics.endFill();
}
}
}

 

it draws out the sprite and it stores the value of 100 for the width and the height. before when u were referencing the this.width it was getting a zero since the sprite was empty. i confirmed this by debugging it and it was infact a zero when no child objects were applied to the sprite. so bascially an empty sprite object will always have a height and width of zero.

 

hope that helps.

 

 

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
studiochris
Posts: 165
Registered: ‎10-26-2010
My Device: BlackBerry® PlayBook™

Re: graphics drawing function success?

[ Edited ]

Oops - didn't read the above completely before posting -- it's already answered.

Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: graphics drawing function success?

That does help a lot.  Thanks for checking it out via code as well.

Contributor
devil007
Posts: 17
Registered: ‎05-12-2010
My Device: odin

Re: graphics drawing function success?

hi i'm newbie in here and sorry i just want to ask, what is super() ?

thanks

Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: graphics drawing function success?

[ Edited ]

The super() function calls the inherited class's constructor. So in this case the inherited class is Shape. (I.e. Sample3d extends Shape - the keyword extends enables the inheritance)

You can learn more about inheritance here:

http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7fc...

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman