PDA

View Full Version : Generating Elements


endzyme
03-25-2005, 05:53 PM
Is it possible to generate dynamic text fields based on flashvars?

ie) Grab text from SQL w/ php or whatever. Parse it into an array for flash (comma delimited or whatever) then foreach the array to make a dynamic text button for each item (while [num_of_items < num_of_items+x] or whatever).

if you need more clarification please Post.

BTW: i've never coded in AS before

Xeef
03-25-2005, 06:04 PM
hi and welcome to As.Org

yes all possible ;)

clarify your problem

endzyme
03-25-2005, 06:38 PM
exellent.

I thought it would be but didnt know where to start without buying an AS book ;-0

Well my problem is this. I have a site that i need to remake without fla files. BUT i use a CMS php product that i want to integrate into a template. By passing FlashVars to the FLA script i want to make menu links dynamically (sql) driven within a certain # of links (3 to 4).


so for example i have 10 links and i want only the first 4. (all that i can do with php).

The real issue is that appart from actually creating 3 or 4 dynamic text fields by hand in flash then setting Vars to each, i cannot figure out how to make text fields generate.

Xeef
03-25-2005, 07:53 PM
here an example
BUT all depends what data you get from the server

FROMPHP = "Name=Xeef,Color=0xFF0000;Name=is,Color=0x00FF00;Na me=Great,Color=0x0000FF";
FROMPHP = FROMPHP.split(";");
W = 0;
for (a=0; a<FROMPHP.length; a++) {
_root.createTextField(a, a, W, 0, 0, 0);
O = _root[a];
O.autoSize = true;
O.textColor = FROMPHP[a].split(",")[1].split("=")[1];
O.text = FROMPHP[a].split(",")[0].split("=")[1];
W += O._width;
}

endzyme
03-25-2005, 08:47 PM
Ok.

Exellent, tested it and it worked. Now, just to understand ActionScript a little more...

is "_root" Some kind of global Variable?

also >> what is a good ref manual, or good learning book for actionscript?

and (sorry) "createTextField(a, a, W, 0, 0, 0)" << what does that exactly mean, what are the 6 parameters and why a, a, W, 0, 0, 0???

are they coordinates? "createTextField(X, Y, #, #, #, #)"???


EDIT: OK so i kinda understand that its essentially a big regexp. where it splits up everything into multiple arrays then uses the parts to build the test.

i guess the only part i do not understand is how flash knows where to draw these instances.

??? anyone? :confused:

Xeef
03-25-2005, 10:42 PM
_root is the main time line all wariables on it you can access from anywhere as _root.Variable

Hmmm no ofense but why in hell do you not take a look to the MM help

createTextField(a, b, c, d, e, f)
a=instanceName
b=depth
c=x coordinate //why W see *
d=y coordinate
e=width of the tectfield //why 0 see **
g=heigth of the textfield // see **

*= W is incrementing each time the length of the textfield so the next textfield come to the end of the fromer one (in the example they are 3 ("Xeef" , "is" , "Great")
**=textfield is set to "autoSize" so what ever size the text will have the textfield will resize to maching size (other wise * woud not work bacause the field woud have a fix width of (let's say 300) but the text woud by just 10-20 width so you woud get BIG gaps betwean)

the last time i had a book in my hand was 7 years ago (lord of the rings) and the last and only time a computer book 15 years ago (commodore what ever not remember on the name (but it wasn't C64)) Hmm ok also one for 23 years Z80 manual in german or english but at this time i neither speak on of them (was just copy the parts which was seams to by code and not description :D)

start doing what you want if you need help ask for it (make a couple of tutorials)
here are plenty of people who will gladly help

endzyme
03-25-2005, 10:51 PM
Thank you very much, this is greatly appreciated :D :D

endzyme
03-25-2005, 11:00 PM
So if i do this it will make the text move down instead of sideways.
so how do i make these into buttons??

also how do i set styles? (ie font, size, etc)

FROMPHP = "Name=Xeef,Color=0xFF0000;Name=isasassa,Color=0x00F F00;Name=Great,Color=0x0000FF";
FROMPHP = FROMPHP.split(";");
//W = 0;
H = 0;
for (a=0; a<FROMPHP.length; a++) {
_root.createTextField(a, a, 0, H, 0, 0);
O = _root[a];
O.autoSize = true;
O.textColor = FROMPHP[a].split(",")[1].split("=")[1];
O.text = FROMPHP[a].split(",")[0].split("=")[1];
//W += O._width;
H += O._height;
}

Xeef
03-25-2005, 11:52 PM
look up "TextField.setTextFormat()" in the help

endzyme
03-28-2005, 04:02 PM
FROMPHP = "Name=Xeef,Color=0xFF0000;Name=isasassa,Color=0x00F F00;Name=Great,Color=0x0000FF";
FROMPHP = FROMPHP.split(";");
//W = 0;
H = 0;
for (a=0; a<FROMPHP.length; a++) {
_root.createTextField(a, a, 0, H, 0, 0);
O = _root[a];
myFormat = new TextFormat();
myFormat.bold = true;
myFormat.font = "Verdana";
O.setTextFormat(myFormat);
O.autoSize = true;
O.textColor = FROMPHP[a].split(",")[1].split("=")[1];
O.text = FROMPHP[a].split(",")[0].split("=")[1];
//W += O._width;
H += O._height;
}

why isn't this working? (textformat wise)

Xeef
03-28-2005, 04:39 PM
FROMPHP = "Name=Xeef,Color=0xFF0000;Name=isasassa,Color=0x00F F00;Name=Great,Color=0x0000FF";
FROMPHP = FROMPHP.split(";");
//W = 0;
H = 0;
for (a=0; a<FROMPHP.length; a++) {
_root.createTextField(a, a, 0, H, 0, 0);
O = _root[a];
myFormat = new TextFormat();
myFormat.bold = true;
//Hmmm hope you have this font :)
myFormat.font = "Calligraphic";
myFormat.size = 25;
myFormat.color = FROMPHP[a].split(",")[1].split("=")[1];
//this you HAVE apply BEFORE
//O.setNewTextFormat(myFormat);
O.autoSize = true;
//not important you can use both ways but now i use the textformat for coloring :)
//O.textColor = FROMPHP[a].split(",")[1].split("=")[1];
O.text = FROMPHP[a].split(",")[0].split("=")[1];
//apply it AFTER the text is set !
O.setTextFormat(myFormat);
//W += O._width;
H += O._height;
}

endzyme
03-28-2005, 04:44 PM
If i set a font then the viewer of the movie has to have that font?

Xeef
03-28-2005, 04:51 PM
YES (and no :p)

you can embed the font in the library but a complet font outline is around 20KB and MORE

so if you have 2-3 fonts in the library it can easily by 100KB plus to your file

endzyme
03-28-2005, 05:13 PM
how do i make the text non selectable?

Xeef
03-28-2005, 05:48 PM
you shoud start using the MM help !

My_text.selectable = false;

endzyme
03-28-2005, 05:49 PM
you shoud start using the MM help !

I searched by came up with nothing! :-/

Xeef
03-28-2005, 06:04 PM
Hmmmmm

then you help system defect (reinstal flash)

endzyme
03-28-2005, 06:17 PM
OK i just didnt know how to read that manual correctly. Well sorry :o .

I got it working so now its a link and grabs the link from the array BUT i want to incorporate animation on rollover and i dont know where to start!?

EDIT: i been playin with it and i dont think i can use .onRollOver {} with TextField. do i have to convert all the text to buttons?

Xeef
03-28-2005, 06:50 PM
yes textfields have no rollover

so conwert it to a movieclip

endzyme
03-28-2005, 07:16 PM
been reading and have no idea how?

Xeef
03-28-2005, 07:29 PM
FROMPHP = "Name=Xeef,Color=0xFF0000;Name=isasassa,Color=0x00F F00;Name=Great,Color=0x0000FF";
FROMPHP = FROMPHP.split(";");
//W = 0;
H = 0;
for (a=0; a<FROMPHP.length; a++) {
O = _root.createEmptyMovieClip(a, a);
O.onRollOver = function() {
trace(this.TXT.text);
};
O.createTextField("TXT", 1, 0, H, 0, 0);
O = O.TXT;
myFormat = new TextFormat();
myFormat.bold = true;
//Hmmm hope you have this font :)
myFormat.font = "Calligraphic";
myFormat.size = 25;
myFormat.color = FROMPHP[a].split(",")[1].split("=")[1];
//this you HAVE apply BEFORE
//O.setNewTextFormat(myFormat);
O.autoSize = true;
//not important you can use both ways but now i use the textformat for coloring :)
//O.textColor = FROMPHP[a].split(",")[1].split("=")[1];
O.text = FROMPHP[a].split(",")[0].split("=")[1];
//apply it AFTER the text is set !
O.setTextFormat(myFormat);
//W += O._width;
H += O._height;
}

endzyme
03-28-2005, 10:36 PM
FROMPHP = "Name=Home,link=http://www.optimapc.com/;Name=Products,link=http://demo.optimapc.com/;Name=Contact Us,link=http://www.optimaisp.net/";
FROMPHP = FROMPHP.split(";");
H = 0;
for (a=0; a<FROMPHP.length; a++) {
O = _root.createEmptyMovieClip(a, a);
O.onRollOver = function() {
O.textColor = 0xFFFFFF;
};
O.onRollOut = function() {
O.textColor = 0xEFEF8E;
};
O.createTextField(a, a, 78, H, 0, 0);
O = O[a];
myFormat = new TextFormat();
myFormat.size = 22;
myFormat.font = "Kristen ITC";
myFormat.url = FROMPHP[a].split(",")[1].split("=")[1];
myFormat.target = "_blank";
O.selectable = false;
O.html = true;
O.autoSize = "center";
//O.textColor = FROMPHP[a].split(",")[1].split("=")[1];
O.textColor = 0xEFEF8E;
//O.onRollOver = O.textColor = 0xFFFFFF;
O.text = FROMPHP[a].split(",")[0].split("=")[1];
O.setTextFormat(myFormat);
H += O._height;
}


This rolls over the last array string only. how do i make an animation for each instance?

also, by changing

O.createTextField(a, a, 78, H, 0, 0);
O = O[a];

will that make each instance have a different name?