Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic container/stage sizing? 1

Status
Not open for further replies.

Leozack

MIS
Oct 25, 2002
867
GB
Hi all - been workin away on makin my tool dynamicly sized. So it can read in an x/y size along with other stuff and set everything up. Currently I've got the container clips positioning and sizing correctly (had issues when referencing clips within clips (the parent of the child would be effected for some reason so moved all clips to root).

But is there a way to set the stage size? Else if the dynamically read size is bigger than the preplaced default it goes off the edge of the stage and disappears. I'm thinking there isn't a way to do this :/

Also, I noticed the image I imported via loadMovie was also enlarged. I knew there was effects like that from using scale etc, but I'm just using a preplaced library item, setting it's x/y and width/height, before I load anything into it. Surely I can do that before loading something and not have the something resized to the same ratio as the container now is to it's original proportions? x.x

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Thanks parseInt worked great today!
It's 3am christmas day but I can't resist coding here and there >_>
I spent a while today rebuilding the project from the ample rather than the other way round.
So far it's all working but I've got to the point where I'm stuck as usual.
Previously the textfields I use were already on the symbol mc's.
But now I'm trying to (allegedly) help things by creating text fields the same way I create the other mc's. Yet - everytime I use the following code, it ruins everything and the overall content shrinks or appears smaller, presumably to fit in a 'large' textbox for some reason ... ?
Code:
var txt = containerMC.infobox_mc.createTextField("info_txt2",100,3,3,containerMC.infobox_mc._width-6,32);
txt.multiline = true;
txt.text = "Info Time!";
I guess I'll have to make them scrollable in due course aswell to fit in content that's too big for it :/

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Upon further inspection, I seem to be getting the following results :
Immediately below saying
Code:
var mc = containerMC.attachMovie("titlebar_mc", "titlebar_mc", 3);
with (mc) {
_width = imgWidth;
(which makes a perfectly correct size box) I can address a textbox prebuilt into the 'titlebar_mc' clip like so
Code:
with (mc.title_txt) {
_x = 3;
_y = 3;
_width = imgWidth-6;
or make a NEW textbox like so
Code:
var txt = containerMC.createTextField("title_time",10,3,3,imgWidth,32);
txt._width = imgWidth-6;
and the same result occurs - the textbox is about 2.5 times the size of the box it's supposed to be in.

If I trace the size of imgWidth it is 800. So the initial box is set to 800. The box inside it I set immediately after to be the same size, and it come out 2.5 times bigger. Errr ... what's wrong? I can only assume it's some kind of parent/child scale thing, since if I MANUALLY set the textbox sizes (either builtin or created) to be something like 320, it fits ok and stops all the correct content being crammed into a vertical pillar about 1/3 of the overall width which is what happens when things go wrong, eg this image


_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Having posted that, I just did further testing from a blank canvas and found you can't assign the result of createTextField to a variable, and that is where I was going wrong.
This is precisely the sort of confusion I moaned about previously whereby doing the same thing or syntax or whatever seems to differ throughout different commands and 2 such. Oh well.
Having just tried to impliment this new discovery, I found the next problem - the textbox only creates if I create it using "this." or "_root.". If I try to use a movieclip to create it, it simply does NOT appear, and I've just tried fiddling about a lot to discover this, eg the following 2 work
Code:
var mc = containerMC.createEmptyMovieClip("test_mc", 1);
this.createTextField("mytext",10,3,3,300,100);
mytext.text = "Testing!";
Code:
var mc = containerMC.createEmptyMovieClip("test_mc", 1);
_root.createTextField("mytext",10,3,3,300,100);
mytext.text = "Testing!";
and the following 2 fail
Code:
var mc = containerMC.createEmptyMovieClip("test_mc", 1);
mc.createTextField("mytext",10,3,3,300,100);
mytext.text = "Testing!";
Code:
var mc = containerMC.createEmptyMovieClip("test_mc", 1);
test_mc.createTextField("mytext",10,3,3,300,100);
mytext.text = "Testing!";
It's no use creating textboxes on the stage instead of withina movieclip since they have to resize/scale with everything else :(

And if I use the textboxes already placed on the library items, the image size/scale thing (see previous post & image) still occurs, meaning I can't do it eitherway without help :(

I hope it's not just me loosing my mind here?

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
I hate to repost but it's gone 4am so I'm heading to bed.
Having given up on the textboxes for now while waiting for help as usual I push on with something else but then get stuck :( It seems I can't make code which I'm sure I had working at 1 point work again, which was to center and rescale loaded images within the image_mc clip.
For instance, if I use the iBg_mc from the example above as the image holder, and use image_mc from the example above as the clip that loads images in and needs to sit central of iBg_mc and proportionately resized to fit, then I tried the fllowing code and it isn't working :( As usual it traces that the 2 sizes are about the same, despite the loaded image being a very big one I made, far bigger than the holder purposefully.
Code:
ContainerMC.image_mc.loadMovie("images/image1.jpg");
Trace(ContainerMC.image_mc._height+" = "+ContainerMC.iBg_mc._height);
ContainerMC.image_mc._height = ContainerMC.iBg_mc._height;
ContainerMC.image_mc._width = ContainerMC.iBg_mc._width;
ContainerMC.image_mc._xscale = ContainerMC.image_mc._yscale = Math.min(ContainerMC.image_mc._xscale, ContainerMC.image_mc._yscale);
ContainerMC.image_mc._x = (ContainerMC.iBg_mc._x+(ContainerMC.iBg_mc._width/2))-(ContainerMC.image_mc._width/2);
ContainerMC.image_mc._y = (ContainerMC.iBg_mc._y+(ContainerMC.iBg_mc._height/2))-(ContainerMC.image_mc._height/2);
I appreciate I've made a few posts in a row here with seperate problems, hopefully the answers to all of them will be simple but I assure you I'm working hard at them before posting here >_<

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
First of all, [tt]createTextField()[/tt] returns the reference to the TextField instance, but only in Flash Player 8. In Player 7 and earlier it returns [tt]Void[/tt].

Secondly, you are not targeting the TextField instance correctly:
Code:
var mc = containerMC.createEmptyMovieClip("test_mc", 1);
mc.createTextField("mytext",10,3,3,300,100);
[b][COLOR=red]mc[/color red][/b].mytext.text = "Testing!";

Thirdly, if you do [tt]loadMovie()[/tt], the asset (JPEG in this case) does not load immediately, therefore you cannot access its properties such as "_width" straight away. Do some [tt]trace()[/tt] - you'll get "zero" or "undefined". Read the doc to see the correct usage of [tt]loadMovie()[/tt].

Kenneth Kawamoto
 
Thanks for the pointers. Glad to hear things are more uniform in newer versions.
But I just tried the exact code you gave there for the textbox in an empty fla and it still didn't show up until I changed the mc. to this. Though I had noticed I had misreferenced it at 4am as you said, it seems even with full regerencing it isn't working?
As for loadmovie, I just read through lots of online docs again on the subject, and tried to use their MovieClipLoader object but it must be for flash mx2004 and higher because it doesn't work, and doesn't even allow specifying :void for the return of a function.

So I still can't seem to make a textbox outside of the root, I still can't get images to load in with a method allowing me to perform things after they're loaded or get it to then center the image (I thought I had this working at some point before using onLoad and a bunch of code I found and included here )

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Of course you must have "containerMC" defined as well:
Code:
[COLOR=red]var containerMC = this.createEmptyMovieClip("container_mc", 1);[/color red]
var mc = containerMC.createEmptyMovieClip("test_mc", 1);
mc.createTextField("mytext",10,3,3,300,100);
mc.mytext.text = "Testing!";

Kenneth Kawamoto
 
Thank, you spotted teh obvious mistake. I'm starting to think I'm too tired to be coding lately.
However, though that example works fine in a blank fla, if I attempt to do the same thing in my project I still get the size issue (see that image I posted above) if I set the created txtbox to be imgWidth-6 in width rather than manually making it, say, 300, which is no problem.

Going back to your original example document, the following code boxes the titlebar movieclip box that is 1 size and it works ok but then using the same variables for size makes the textbox over twice as big
Code:
    var mc = containerMC.attachMovie("titlebar_mc", "titlebar_mc", 3);
    with (mc) {
        _x = margin;
        _y = margin;
        _width = imgWidth;
        _height = titleHeight;
    }
	mc.createTextField("title_time",10,3,3,imgWidth,titleHeight);
	mc.title_time.multiline = true;
	mc.title_time.border = 1;
	mc.title_time.text = "Title time!";

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top