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
Highlighted
Developer
Posts: 200
Registered: ‎03-10-2011
My Device: Not Specified
Accepted Solution

How to lay things out?

So I've been learning how to use containers, I've had some problems but I've been able to solve them. Anyway, I was wondering what would be the best way to layout a basic options screen?

 

I want to have a label, with a component next to it, for example "Enabled: [on | off]". And then have another option listed under that with the same format like "Favorite Color: [dropdown list]". If I make a container with a vertical flow and add the labels and control they're all in a long list, so to keep the labels and components in groups I find I need to put every row into its own container with horizontal flow. This could lead to a huge amount of code duplication.

 

Is there a better way to do this? Should I stick with this method but find a way to keep code duplication from happening? Or should I use a listbox with some sort of custom cell renderer?

Developer
Posts: 158
Registered: ‎01-11-2010
My Device: 9700 | 9900 | PlayBook | Dev Alpha
My Carrier: Many :)

Re: How to lay things out?

i dont think it would be that much doce duplication:

 

 

public function layOutMyContainer(c:ObjectContainer){

c.property = this;
c.OtherProperty = that;

}

 

 

then all you need to do is

 

 

// decelerations at the beginning of your class or method
public var MyFirstContainer:ContanerObject = new ContainerObject();
public var MySecondContainer:ContanerObject = new ContainerObject();
public var MyThirdContainer:ContanerObject = new ContainerObject();
public var MylastContainer:ContanerObject = new ContainerObject();


....


// code inside of the LayoutUI method, possibly?

layOutMyContainer(MyFirstContainer);
addChild(MyFirstContainer);

layOutMyContainer(MySecondContainer);
addChild(MySecondContainer);

 

 

the program i wrote has a few duplicated containers, so instead of clutter up my main buildUI() method, i just created a function to set the properties of a passed container.  this way, my buildUI() function is a *lot* cleaner, and when i need to make a change to how the container properties are done, only need to change the settings once.

 

 

Or, somebody else might have a completly different solution not involving containers at all Smiley Happy

- - - - - - - - - -
Developer
Posts: 200
Registered: ‎03-10-2011
My Device: Not Specified

Re: How to lay things out?

Ah ok. Thanks for the fast reply! I think I'll probably use a method like you showed here. I just thought that if I end up with many rows the resulting code could be a little bloated maybe? But I don't think that there will be that many rows.

Also, another problem I'm having is. I seem to have to set up my containers in my classes constructor. I would have preferred to use a method like shown in the tutorials. Where you have a separate function like 'initializeUI'. But when I do that the result is no containers and all my objects that I added to the containers visible on the stage unaffected in position by the actual containers that they were supposed to be in. I hope that makes sense.
Developer
Posts: 158
Registered: ‎01-11-2010
My Device: 9700 | 9900 | PlayBook | Dev Alpha
My Carrier: Many :)

Re: How to lay things out?

it does!  containers are very fickle, but JRab helped me out.

 

try this

 

 

MyParrentContainer.layout()

 

assuming MyParrentContainer is your container with everything else in it.

 

- - - - - - - - - -
Developer
Posts: 200
Registered: ‎03-10-2011
My Device: Not Specified

Re: How to lay things out?

Oh! I'll definitely try this. Thanks so much for the help! Smiley Very Happy
I'll mark your post as the solution once I get it working.
Developer
Posts: 158
Registered: ‎01-11-2010
My Device: 9700 | 9900 | PlayBook | Dev Alpha
My Carrier: Many :)

Re: How to lay things out?

Dont mark anything until it's working Smiley Happy

 

Good luck!  (i spent a *whole week* trying to figure out a bug similar to yours only to have JRab drop the .layout() on me)

 

 

- - - - - - - - - -
Developer
Posts: 200
Registered: ‎03-10-2011
My Device: Not Specified

Re: How to lay things out?

[ Edited ]

YES!! It works! Thanks SO much DTater! Smiley Very Happy Kudos and solution marks for you.

 

Just one more question. When you defined a new container, is it ok to initialize the container with the variable?

 

For example:

public var MyContainer:Container = new Container();

 

Instead of:

public var MyContainer:Container;

function MyClassFunc() {

     MyContainer = new Container();
}

 

The tutorials seem to use something like the second. Is there any advantage to this? In my opinion the first looks best.

 

EDIT: I just noticed you used "ContainerObject()" instead of "Container()". Why is that?

Developer
Posts: 158
Registered: ‎01-11-2010
My Device: 9700 | 9900 | PlayBook | Dev Alpha
My Carrier: Many :)

Re: How to lay things out?

 


Kai001 wrote:

YES!! It works! Thanks SO much DTater! Smiley Very Happy Kudos and solution marks for you.

 



 

im so excited Smiley Very Happy Yay! 

 

 


Kai001 wrote:

 

Just one more question. When you defined a new container, is it ok to initialize the container with the variable?

 

Uhh, this has to deal with pointers and the like.

 

when you simpily create a new var, but dont initalize it (like so)

 

public var myVar:varType;

public var tmpInt:int;

 

 

all you're doing is telling the compiler to create a pointer to an integer.  this pointer is an arrow, that points to nothing... until you do:

 

myVar = someValue;

public var tmpInt:int = new int();

 

this explicitly makes the pointer, but now the pointer points to an address in memory that contains someValue or is the proper size (but has no value) to store an int.

 

when / if you use Cor C++ you'll learn *allllll* about pointers and the like.

 

the reason for declaring the variables in different places is the *scope* of the variable.  when you declare the variable *outside* of any function (meaning it is in the CLASS definition) then it becaomes a class variable and as such, can be accessed by any function in the class and possibly other classes.

 

an array is a class that has a LENGTH attribute.  the LENGTH attribute is not declared inside any function; it is a class variable... this is why / how you are able to do

 

 

trace(myArray.length);

 

 

as this tells the compiler to go find the value that array's length.

 

 

if you don't need your variables to be accessable to other classes / methods, then you can just declare them in the function.

 

i just finished a library where i do this all the time.

 

 

public myFunction(array){
for(int i=0 ; i < array.length ; i++ ){ //work magic on array }
}

 

this creates a variable i (of type int) and sets it to 0.  this was created INSIDE the function so it will not be accessable to any other function or class and will die / be destroyed when the for loop is over and teh function exits.

 

for more, google variable scope

 

 


Kai001 wrote:

 

 

 

EDIT: I just noticed you used "ContainerObject()" instead of "Container()". Why is that?


because i was doing by hand from memory.  i forgot the exact name of the class, but you got my point.

 

same goes for the for loop in the example above... that won't compile in ActionScript or C, but it will (probably) in C++.  I use a lot of different languages, and they all bleed together after a while.

 

- - - - - - - - - -
Developer
Posts: 200
Registered: ‎03-10-2011
My Device: Not Specified

Re: How to lay things out?

Wow, you didn't have to write such an elaborate reply for me. Smiley Very Happy Thank you very much!

 

And yes, I have experience in C++, learning the basics of writing 3D DX9 games. I only knew of the very most basics of pointers. (In other words almost nothing Smiley Tongue)

 

 I tend to make most variables public. I really don't see how there's an advantage to making them private most of the time.

Developer
Posts: 158
Registered: ‎01-11-2010
My Device: 9700 | 9900 | PlayBook | Dev Alpha
My Carrier: Many :)

Re: How to lay things out?

for security, mainly.

 

one of my libraries needs the developer to fill in some sensitive information (an API key).  this string as well as the URL the library quers against does not need to be public.  it's kept private so there is no way other classes could read or write to it.

- - - - - - - - - -