Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-18-2003, 01:59 PM   #1
subquark
yep, it's martini time!
 
subquark's Avatar
 
Join Date: Jun 2002
Location: Boston
Posts: 1,983
Default one template, many looks?

I searched and also went through the tutorials. But once again, I don't even know the approach so am not sure what to look for. I know the result I want (become a world renowned mx guru and make more money that Bill Gates). Sorry, I dozed off for a sec . . .

The tutorials that came closest were Tutorial 28 attachMovie and Tutorial 32 LoadVariables and LoadVars Objects

What I would like to do is by using actionscript generate a simple interface. This part I think I can do.

ActionScript Code:
boxOne_mc._x = 100; boxOne_mc._y = 100; boxTwo_mc._x = 200; boxTwo_mc._y = 100; boxOne_mc._x = 300; boxOne_mc._y = 100; btnOne_mc.x = 5; btnOne_mc.y = 100; et cetera

where I have some five movie clips that I will always want to show, but have them arranged in two different manners. To keep this example simple. Let's say I want one swf to have 5 horizontal boxes and the other to have 5 vertical boxes (I will also apply the same to a series of buttons, but that's later).

So I would like to create what??? Is it an array? A function? See I'm totally lost as to where to start.

I have these movie clips (boxes and buttons) and also a news box a la Jesse's tutorial

ActionScript Code:
holder.loadVariables("file.txt");

just point me to a thread, I'm sure that is has been done a billion times (a billion, hmm, Bill Gates . . . did you know that a million dollars is to Bill Gates like 42 cents is to the average American?).

Thanks!
__________________
mr. olive . . . hold on to your monkey!
subquark is offline   Reply With Quote
Old 05-18-2003, 02:34 PM   #2
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Hm... I don't understand your question regarding how the buttons should be laid out after reading the data from the text file... Can you draw something and upload it so that my exhausted brain can understand how it is going to be looking like???

Oh... I am not sure if I have told you this or not, but here it is...
Do not ever ever ever never use loadVariables() function in FMX unless you are exporting your movie in F5 format... That's for your own sake...
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 05-18-2003, 03:20 PM   #3
subquark
yep, it's martini time!
 
subquark's Avatar
 
Join Date: Jun 2002
Location: Boston
Posts: 1,983
Default

thanks CyanBlue! I'm trying to make two interfaces from one. So that for layout A the movieclips are arranged as such and for mc B they are arranged another way.

Same movie clips just arranged differently. So their positions are dictated by some set of parameters. Set of parameters A (position) yields layout A . . .

Here's the look (two largest sets of blocks are content mc, the little ones are button mcs).

http://www.subquark.com/footer/layout.gif

and then actually I would like each "layout" to be able to load content X or content Y. But I thinks I'll do this with loadURL for jpg loading (I think).

Forget the txt file thing, that's to load text in another mc.

Thanks for the loadVars tip!
__________________
mr. olive . . . hold on to your monkey!

Last edited by subquark; 05-18-2003 at 03:23 PM.
subquark is offline   Reply With Quote
Old 05-18-2003, 03:54 PM   #4
subquark
yep, it's martini time!
 
subquark's Avatar
 
Join Date: Jun 2002
Location: Boston
Posts: 1,983
Default

maybe something like this:

ActionScript Code:
_root.createEmptyMovieClip("myMC1", 1); _root.createEmptyMovieClip("myMC2", 2); _root.createEmptyMovieClip("myMC3", 3); myMC1._x = 30; myMC1._y = 30; myMC2._x = 30; myMC2._y = 50; myMC3._x = 30; myMC3._Y = 150; loadMovie("movie1.swf", myMC1); loadMovie("movie2.swf", myMC2); loadMovie("movie3.swf", myMC3);

but this uses external swfs, I'd like to use mc's from the library.

totally clueless . . .

I need a function with parameters (I think), I'll keep searching here and in the mountain of books. Sometimes I feel like such a simpleton (boo hoo).
__________________
mr. olive . . . hold on to your monkey!
subquark is offline   Reply With Quote
Old 05-18-2003, 03:54 PM   #5
retrotron
thinking is design
 
retrotron's Avatar
 
Join Date: Apr 2003
Location: UK
Posts: 1,292
Default

I'll throw in my two cents here, though wait for Cyan's as it will assuredly be better.

Sometimes when I build these kinds of things, I write a function called "buildLayout()" or something similar (this is always part of an object for me, but it would work otherwise too). I pass one parameter: an associative array called "layoutInfo" that contains many variables. E.g.:

ActionScript Code:
// define parameters array var layoutInfo = new Array(); layoutInfo.buttons = "horizontal"; layoutInfo.button1_startx = "25"; layoutInfo.contentStyle = "style1"; etc... // call function buildLayout(layoutInfo);

The function begins by initializing the values of the layoutInfo array by checking if the value is defined, and if not, it sets the default value.

ActionScript Code:
function buildArray(x) {   if (x.buttons == undefined) { x.buttons = "vertical"; }   if (x.button1_startx == undefined) { x.button1_startx = 0; }   etc...   if (x.bgColor == undefined) { x.bgColor = "0x000000"; }   etc.. } // end buildArray()
This lets the developer fill out only those values of the layoutInfo array that she wants to alter. For example, notice that I did not define layoutInfo.bgColor in the layoutInfo array, so the function will simply assign a default value.

Then the function builds the interface according to the values:

ActionScript Code:
function buildArray(x) {    // above initialization code here ....   // define the main movie clip which will contain all the others   // and assign its background color to x.bgColor ...   // build button interface   if (x.buttons == "vertical") {     // code here to build the buttons vertically,     // starting at x.button1_startx ...   } else if (x.buttons == "horizontal") {     // code here to build the buttons horizontally,     // starting at x.button1_startx ...   } // end if statement   // build content interface ....   if (x.contentStyle == "style1") {     // code here to arrange the content _mcs via one style   } else if (x.contentStyle == "style2") {     // code here to arrange the content _mcs via another style   } // etc.   // and so on until everything is complete ... } // end buildLayout()
This lets you have everything customizable, everything from fonts to fontsize to alpha transparencies, to images, etc. If you want any element to be customizable, simply include an element for its definition in the layoutInfo array. Again, since it's an associative array and everything is set to a default value, the user can send as many elements as she likes. For example,

ActionScript Code:
// define parameters var layoutInfo = new Array(); layoutInfo.bgColor = "0x0000cc"; layoutInfo.txtColor = "0xFFFFFF"; // call function buildLayout(layoutInfo);
this would do everything default except for bgColor and txtColor, but one could also send a layoutInfo array with all 200 elements defined (assuming your interface had that many customizable elements).

Anyhoo, I've found this method to be very nice in the past, and very reusable.

Hope something here gives you some ideas.
retrotron is offline   Reply With Quote
Old 05-18-2003, 04:40 PM   #6
subquark
yep, it's martini time!
 
subquark's Avatar
 
Join Date: Jun 2002
Location: Boston
Posts: 1,983
Default


OMG! That's it!!! CyanWho? (oh oh that rhymes too)

Yeah CyanBlue is the friggin' CodeBeast, however, you have hit the nail on the head. Exactly what I was after (I think). I knew there was a way.

Thank you so much! So do you also create your buttons in actionscript? I have a whole bunch (19) of movie clip buttons but wanted to also see about making those on the fly. Simple looking text buttons but it would be nice if a function could be made to create the buttons and label them. See, I am so far behind someone like you that it all seems so hard. But I know it's doable (sp?).

BillyT has a tutorial where he creates buttons but they are not labelled . . .

http://www.actionscript.org/tutorial...nt/index.shtml

and his code goes like this:

ActionScript Code:
//create our buttons for(i=1;i<5;i++){         _root.createEmptyMovieClip("button"+i, 100+i);         _root["button"+i].lineStyle(2, 0x000000, 100);         _root["button"+i].beginFill(0xFF0000, 100);         _root["button"+i].moveTo(-25, -10);         _root["button"+i].lineTo(25, -10);         _root["button"+i].lineTo(25, 10);         _root["button"+i].lineTo(-25, 10);         _root["button"+i].endFill(-25, -10);         _root["button"+i]._x=i*60;         _root["button"+i]._y=25; } _root.createEmptyMovieClip("button"+i, 100+i); _root["button"+i]._x=i*60; _root["button"+i]._y=25;
__________________
mr. olive . . . hold on to your monkey!
subquark is offline   Reply With Quote
Old 05-18-2003, 06:05 PM   #7
retrotron
thinking is design
 
retrotron's Avatar
 
Join Date: Apr 2003
Location: UK
Posts: 1,292
Default

What do you mean by "labelled"? Are you referring to the instance name or the text that is displayed on the face of the button?

You can definitely use AS to create buttons dynamically. I built a function (maybe an object, I can't remember) a while back that creates buttons on the fly, and I think it even uses the above-mentioned array thingy to customize colors, font, size, text-placement inside the button, and even whether the background is solid or alpha transparent. It also lets you define the instance name and the text on the face of the button, if that's what you're after. I'm not at my home computer, so I can't dig up the code, but I'll post it when I get the chance if you like (or you can build your own!).

Of course, this is re-inventing the wheel a bit since components solve this problem with a simple "attachMovie()" method, but I always say it's good to reinvent the wheel at least a few hundred times. Who do I say this to, you ask? Mostly myself, and on occasion the lamp in the corner.
retrotron is offline   Reply With Quote
Old 05-18-2003, 06:17 PM   #8
subquark
yep, it's martini time!
 
subquark's Avatar
 
Join Date: Jun 2002
Location: Boston
Posts: 1,983
Default

doh! components! thanks! I did not even explore that! they can be reskinned and all that (but now I have to read up on eventHandlers . . .)

as you can tell, I'm a newbie (well, I've been banging my head for a year or more) but how do I use something like this to place my button mcs?

ActionScript Code:
for(i=1;i<5;i++){ _root.createEmptyMovieClip("button"+i, 100+i); _root["button"+i]._x=i*60; _root["button"+i]._y=25; }

it's the real basic questions that I can't grasp . . .



Thanks, you have shed some light on me and given me hope. I really, really appreciate this!
__________________
mr. olive . . . hold on to your monkey!
subquark is offline   Reply With Quote
Old 05-18-2003, 07:20 PM   #9
retrotron
thinking is design
 
retrotron's Avatar
 
Join Date: Apr 2003
Location: UK
Posts: 1,292
Default

Your code looks exactly right to me.

However, these movie clips are currently empty, there's no drawing or loaded conent in them, so you won't see anything on the stage when you run this code.

Try drawing a line so you can see something when you test it:
ActionScript Code:
for(i=1;i<5;i++){         _root.createEmptyMovieClip("button"+i, 100+i);         _root["button"+i].moveTo(0,0); // move pen to 0,0         _root["button"+i].lineTo(50,0); // extend a line 50px to the right         _root["button"+i]._x=i*60; // move line to these coordinates         _root["button"+i]._y=25; }
retrotron is offline   Reply With Quote
Old 05-18-2003, 08:24 PM   #10
subquark
yep, it's martini time!
 
subquark's Avatar
 
Join Date: Jun 2002
Location: Boston
Posts: 1,983
Default

thanks retrotron, you have helped make this day much more pleasant. I'm trying to do some layouts for a possible fulltime employer and really want to deliver some nice interfaces.

they just asked to layout one interface from the top three candidates, and rather than just doing that like I normally would, I wanted to generate as much as I could via AS. and maybe give them two interfaces with one swf by just changing a few lines of code. like your firts example, that makes a lot of sense and is very efficient and well done (i presume you work in the biz and do quite well).

here is a freebie site I'm doing: http://www.rockagainstsuicide.com/flash and it's still in the early stages but is standard in that it's a bunch of buttons that were placed on the stage.

for this project, i wanted to dynamically produce as much as i can (but i just don't have the knowledge yet).

the example with the empty movie clips; well I was wondering how I could take my buttons (instance names: home_btn, specials_btn, etc) and populate the stage with them at set positions. so that the loop would go through all the button names (so change them to one_btn, two_btn, . . .) and place them 25 pixels down from the last and so on.

BUT, that's what I don't know how to write: a loop that will count and place the buttons at set distances (x for horizontal buttons and y for vertical.
__________________
mr. olive . . . hold on to your monkey!
subquark is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:10 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.