PDA

View Full Version : Creating textfields.



urieljuliatti
April 27th, 2009, 07:52 PM
Hey folks, I'm testing my knowledge as a beginner and tryin' toi get it step by step.

On this recent project I am creating a menu with 3 buttons and respectives texfields..

But i don't know how add the text names from the Array into the MovieClip..

Check out:




// Vars
var allButtons:int = 3;
var spacing:Number = 50;
var navBar:MovieClip = new MovieClip();
var textTitles:Array = new Array("Home", "Empresa", "Portfolio");
var total:Number = textTitles.length;

stage.addChild(navBar);

// Listeners


navBar.addEventListener(MouseEvent.CLICK, navega, false, 0, true);

// Functions

for (var i:int = 0; i < allButtons; i++){ // Duplicating
var menu:MovieClip = new Sessoes(); // creating var to the Abutton (MovieClip from the Library)
menu.name = "sessao" + i; // Creating instance...
menu.x = spacing + i * (menu.width + spacing); // space between them
menu.y = 25; // height
titulo_txt.text = menu [ i ]; // problem here!
navBar.addChild(menu);

}
function navega (e:MouseEvent):void {
nextSection = e.target.name;
play();
}




What can I do?

.ral:cr
April 28th, 2009, 02:02 AM
menu.titulo_txt.text = textTitles [ i ]; ?

i would send almost anything through the constructor anyway.

_dfm_
April 28th, 2009, 04:24 AM
yes, I agree. I will also send any data needed for the constraction of the button into constructor. Also there migth be problem setting text name line this menu.titulo_txt.text = textTitles [ i ], you can try also TextFiend(menu["titulo_txt"]).text = textTitles [ i ]; I'm not sure but here Flash may throw you you error because cannot read property titulo_txt, when is compiling.

Also I suggest you to create Array like this:

var textTitles:Array = ["Home", "Empresa", "Portfolio"];

new Array consctructor is slower then [].

.ral:cr
April 28th, 2009, 05:16 AM
you'll lose strict typing with this menu["titulo_txt"]

urieljuliatti
April 28th, 2009, 06:56 PM
you'll lose strict typing with this menu["titulo_txt"]

Nothing worked..

snickelfritz
April 28th, 2009, 07:50 PM
This code dynamically creates a number of labeled buttons equal to the length of the textTitles array.
A dynamic textfield, instance name: btnLabel, is nested within the MovieClip Class: Sessoes.
This code is on frame1 of the main timeline.


var nextSection:String = "";
var spacing:Number = 50;
var textTitles:Array =
[
"Home",
"Empresa",
"Portfolio"
];

var navBar:Sprite = new Sprite();
addChild(navBar);

for (var i:uint = 0; i < textTitles.length; i++)
{
var _menu:MovieClip = new Sessoes();
_menu.id = i;
_menu.x = spacing + (i * (_menu.width + spacing));
_menu.y = 25;
_menu.buttonMode = true;
_menu.mouseChildren = false;
_menu.btnLabel.text = String(textTitles[i]);
_menu.addEventListener(MouseEvent.MOUSE_DOWN, navega, false, 0, true);

navBar.addChild(_menu);
}

function navega(e:MouseEvent):void
{
nextSection = String(textTitles[e.target.id]);
trace(nextSection);
}

urieljuliatti
April 28th, 2009, 10:04 PM
This code dynamically creates a number of labeled buttons equal to the length of the textTitles array.
A dynamic textfield, instance name: btnLabel, is nested within the MovieClip Class: Sessoes.
This code is on frame1 of the main timeline.
ActionScript Code:

var nextSection:String = "";
var spacing:Number = 50;
var textTitles:Array =
[
"Home",
"Empresa",
"Portfolio"
];

var navBar:Sprite = new Sprite();
addChild(navBar);

for (var i:uint = 0; i < textTitles.length; i++)
{
&nbsp;&nbsp;&nbsp;&nbsp;var _menu:MovieClip = new Sessoes();
&nbsp;&nbsp;&nbsp;&nbsp;_menu.id = i;
&nbsp;&nbsp;&nbsp;&nbsp;_menu.x = spacing + (i * (_menu.width + spacing));
&nbsp;&nbsp;&nbsp;&nbsp;_menu.y = 25;
&nbsp;&nbsp;&nbsp;&nbsp;_menu.buttonMode = true;
&nbsp;&nbsp;&nbsp;&nbsp;_menu.mouseChildren = false;
&nbsp;&nbsp;&nbsp;&nbsp;_menu.btnLabel.text = String(textTitles[i]);
&nbsp;&nbsp;&nbsp;&nbsp;_menu.addEventListener(MouseEvent.MOUSE_DO WN, navega, false, 0, true);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;navBar.addChild(_menu);
}

function navega(e:MouseEvent):void
{
&nbsp;&nbsp;&nbsp;&nbsp;nextSection = String(textTitles[e.target.id]);
&nbsp;&nbsp;&nbsp;&nbsp;trace(nextSection);
}




"TypeError: Error #1010: A term is undefined and has no properties.
at AdvancedNavigation_fla::MainTimeline/AdvancedNavigation_fla::frame1()"