?
Solved

Unexpected Behavior when dynamically creating containers in AS3

Posted on 2009-05-12
4
Medium Priority
?
268 Views
Last Modified: 2013-11-11
I am probably trying to do something a little too fancy for my level of experience, but its sort of intriguing me. I am creating a dynamic tabNavigator based on an Array. I have created a for loop to dynamically create this it run time.

In the first Tab, I am trying to add an image and a rich text editor in an HBOX, but it only shows the second child that I added. i cannot find an example online on how to make this work and i couldnt find anything on the livedocs.adobe site either.

I have attached the code below. This site has been very helpful and I have learned more in the last week from this site then I have from reading 3 FLex books.
//Lets build the TabNavigtor.
for (var i:int = 0; i < prodEditArray.length; i++)
{
	var source:String = new String();					
	var _canvas:Canvas = new Canvas();	
	var _image:Image = new Image();	
	var _vboxLeft:HBox = new HBox();	
	var _vboxRight:HBox = new HBox();
	var _hboxParent:HBox = new HBox();	
	var _rte:RichTextEditor = new RichTextEditor();	
	var _textArea:TextArea = new TextArea();	
 
	_image.height = 1104;
	_image.width = 816;
	_image.source = prodEditArray[i].imageDir + prodEditArray[i].imageName;
 
	_textArea.id = prodEditArray[i].labelID;
	_textArea.editable = "true";
	_textArea.width = 100;
	_textArea.height = 200;
	_textArea.x = 300;
	_textArea.y = 300;
	_textArea.enabled = "true";
	_textArea.text = "who knew this would work";
 
	_canvas.addChild(_image);
	_canvas.addChild(_textArea);
	_canvas.visible = "true";
 
	_vboxLeft.addChild(_canvas);
	_vboxLeft.visible = "true";					
	_vboxLeft.verticalScrollPolicy = "on";	
 
	_vboxRight.addChild(_rte);
	_vboxRight.visible = "true";					
 
	_hboxParent.label = prodEditArray[i].page;	
	_hboxParent.addChild(_vboxLeft);
	_hboxParent.addChild(_vboxRight);	
 
	trace (_hboxParent.numChildren); //this always says 2.					
 
	this.TabEdit.addChild(_hboxParent);						
}

Open in new window

0
Comment
Question by:20lbMonkey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 39

Expert Comment

by:blue-genie
ID: 24371999
are you not just adding the one child on top of the other since you're not changing your location where you load it (try setting the x and y and see)
0
 
LVL 37

Accepted Solution

by:
zzynx earned 2000 total points
ID: 24372028
>> trace (_hboxParent.numChildren); //this always says 2.
Meaning the _vboxLeft and _vboxRight are added for sure.

>> but it only shows the second child that I added
So you see the _vboxRight and not the _vboxLeft?
That's a visualisation problem.

Could you try:

_vboxLeft.percentWidth = 100;
_vboxLeft.percentHeight = 100;
_canvas.percentWidth = 100;
_canvas.percentHeight = 100;
_vboxLeft.addChild(_canvas);

btw, in my opinion, all the instructions

... = "true";

should be

... = true;

in MXML code you should have those " " but not in AS code
0
 

Author Closing Comment

by:20lbMonkey
ID: 31580828
It was a visualization problem. Thank you for your help.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24464797
You're welcome.
Thanx 4 axxepting
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses
Course of the Month10 days, 17 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question