PDA

View Full Version : Attaching TextFields to a ScrollPane


chad
07-25-2006, 04:53 PM
Is it possible to attach dynamic TextFields to a ScrollPane? I'm able to attach a MovieClip from my library which contants a Dynamic Text inside of it (given an instance name, of course) and access/modify that Text, however, this is insufficient because then I'm forced to handle the width and height of the Text Field manually. I want to dynamically create TextFields and attach them directly to my ScrollPane (or directly to a MovieClip that is set to the contentPath of the ScrollPane).

An effective, yet insufficient example:

pane.contentPath="body"; //an empty movie clip in the library
pane.content.attachMovie("mc_with_text","text_field",0);
pane.content.text_field.text.text="This works, but sucks.";


An ineffective, yet seemingly sufficient example:

pane.contentPath="body"; //an empty movie clip in the library
pane.content.createTextField("text_field",0);
pane.content.text_field.text="This doesn't work, but I want it to!".


Is there a way to use createTextField on the contents of a ScrollPane?

acolyte
07-25-2006, 04:58 PM
Hi Chad

//ATTACH SCROLLPANE
createClassObject(mx.containers.ScrollPane, "myScrollPane", 400, {x:200,
y:200});
myScrollPane.setStyle("borderStyle", "none");

//YOU NEED A CLIP IN YOUR LIBRARY WITH LINKAGE ID SET TO 'paneHolder'
myScrollPane.contentPath = "paneHolder";
var paneContent = myScrollPane.content;

//YOU'LL THEN NEED TO BUILD OR ATTACH YOUR CONTENT INTO 'paneContent'
//SOMETHING LIKE THIS:

paneContent.createEmptyMovieClip("tunesClip"+i, 410+i); //ETC, ETC...

//AND YOU CAN SET SOME PARAMETERS LIKE THESE
myScrollPane._x = 4;
myScrollPane._y = 174;
myScrollPane.setSize(400, 266);
myScrollPane.hScrollPolicy("off");
myScrollPane.vScrollPolicy("auto");
myScrollPane.vPosition = 0;


please the next Time just post this in the Components Area .
The as 2.0 Area is meant to be a OOP Board and normaly working with Code and Components is
basically as 2.0

btw i found the info by just typing >attach scrollpane by code< in the google Mask on the very first Thread

thnx m@

chad
07-25-2006, 05:03 PM
acolyte,

This is an ActionScript issue, dynamically creating TextFields with ActionScript.

Your reply doesn't even address the problem.

acolyte
07-25-2006, 05:46 PM
Mhh sry i dont get you ,

No your Thread is called Attaching TextFields to a ScrollPane

and you can add the Textfield right here :


//YOU'LL THEN NEED TO BUILD OR ATTACH YOUR CONTENT INTO
paneContent.createEmptyMovieClip("tunesClip"+i, 410+i);
tunesClip.createTextField ........................................


this should just show of the analogy of doing it dynamic
so in my opinion i am right.

Sry if this sounded to harsh ....
but you will get better and faster answers here if
you choose the right categorys to post
- in general

thats it

chad
07-25-2006, 05:49 PM
Right.. you're doing exactly the same thing that I described as not working. Thanks anyway.

acolyte
07-25-2006, 05:56 PM
Right.. you're doing exactly the same thing that I described as not working. Thanks anyway.

but your Code is missing the Line :

var paneContent = myScrollPane.content;

can you upload a .fla

btw here it works ?


//ATTACH SCROLLPANE
createClassObject(mx.containers.ScrollPane, "myScrollPane", 400, {x:100, y:100});
myScrollPane.setStyle("borderStyle", "none");
//YOU NEED A CLIP IN YOUR LIBRARY WITH LINKAGE ID SET TO 'paneHolder'
myScrollPane.contentPath = "paneHolder";
var paneContent = myScrollPane.content;
//YOU'LL THEN NEED TO BUILD OR ATTACH YOUR CONTENT INTO 'paneContent'
//SOMETHING LIKE THIS:
paneContent.createEmptyMovieClip("tunesClip", 410);
paneContent.tunesClip.createTextField("test_txt", 50, 50, 0, 100, 300);
paneContent.tunesClip.test_txt.multiline = true;
paneContent.tunesClip.test_txt.wordWrap = true;
paneContent.tunesClip.test_txt.text = "your scroll text goes here";
//ETC, ETC...
//AND YOU CAN SET SOME PARAMETERS LIKE THESE
myScrollPane._x = 0;
myScrollPane._y = 0;
myScrollPane.setSize(200 >>/ width, 266 >>/height);
myScrollPane.hScrollPolicy("off");
myScrollPane.vScrollPolicy("auto");
myScrollPane.vPosition = 0;


you need to take care that your ScrollPane height is smaller than your Textfield height
if this is not the case nothing will scroll - i think that was the problem

chad
07-25-2006, 06:59 PM
I don't need


var paneContent = myScrollPane.content;


I'm referencing pane.content directly. Everything is set up correctly. Like I said, I can attach MovieClips but not TextFields. That is my question... can TextFields be dynamically attached to the .content of the ScrollPane?

Look at my original post...

Xeef
07-25-2006, 07:04 PM
it can

but not so

pane.content.createTextField("text_field",0);

createTextField takes 6 arguments and NOT 2 !

chad
07-25-2006, 07:07 PM
Xeef:

You're right, it does take 6 arguments. I assumed that the last four were optional and had default values. Easy fix, thanks for pointing that out.

acolyte
07-25-2006, 07:07 PM
Hi Chad ,

why do you need this you also can refer to a Xml Node from there ?
You got Styled Text in a Textfield in Flash ?, -why dont you put the Textfield in the Movieclip and attach the Movieclip the Result will be the same as
when you fill in the Text dynamical.

As shown in the Example above first attache the "Riser" Movieclip to the Scrollpane then in the Riserclip create A Textfield and fill it with Text

best greets M@

- Hi Xeef and thanx for poining this out :cool: