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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get the height and width of my flash movie 1

Status
Not open for further replies.

Themuppeteer

Programmer
Apr 4, 2001
449
BE
Hello,
Another easy question that I can' figure out but I'll be glad to give you a star if you can (as I always do when someone helps me).
I'm making a ball that bounces around the screen movie,but:
how do I know the width and height of my flash movie ?
I have taken _level0.width and _level0.height, but my ball
just flies out of the screen and _level0.width and height increase!
How does this come and why doesn't my check
if(x>_level0.width)
{
left=true;
}
work ? Greetz,

The Muppeteer.
themuppeteer@hotmail.com

Don't eat yellow snow...
 
MovieClips (and movies) are measured by the size of their contents in a particular frame ... so if you have a square graphic 10px by 10px in the middle of a stage which is 550px by 400px, and get the height and width of the stage like this:

movieHeight = _root._height;
movieWidth = _root._width;

you will get these values:

movieHeight = 10
movieWidth = 10

Unless you make a background graphic which is the entire size of your stage and keep it on screen at all times, you will get inaccurate (and varying) values for the width and height. And if you DO use the background graphic, there's not much point in trying to dynamically calculate it's width and height.

My advice is just put the values in literally.
 
If you're using Flash MX you can access the .height and .width properties of the Stage object which will work even if the Flash Player window is resized. Slainte

 
ok, this is my plan,
I create a rectangle around the screen (not filled) and then I ask the width and height of that.
I made the rectangle,converted it to graphic,named it border and than var w=_root.border._width; and it still doesn't work. I think I'm getting depressed... these things are quit obvious for me at first,but then it does not work and it seems there is no easy logical way to do it... Greetz,

The Muppeteer.
themuppeteer@hotmail.com

Don't eat yellow snow...
 
You can't name a graphic. Try this code (leave the graphic on stage):

w = _root._width
 
What wrong with...?

if(x> your_actual_stage_width_in_pixels)
{
left=true;
}
Regards,

new.gif
 
Well spotted as usual, old. Trying to "find" the size of your stage is a bit daft when you know it. Although it would be nice to be able to work it out (somehow properties are always more appealing than literals).
 
Ok! I'm out of here!
I'll let you kids battle it out! Regards,

new.gif
 
grrrfffmmmmm (thunder and lightning)!!!!!!

you wanna know what it was ??
2 things,

1)My ball went right and down,so the lower right corner got
to the end of the movie and kept on going (because it is
the upper left corner that checks the boudries) and
therefore the width and height became bigger and bigger
(why??),so the upper left corner never reached the lower
right corner...thats why I thought _root._width didn't
work...but it did work.
So in the load event I put the w and h values in global
vars and problem solved.
2)I forgot the _ before my x in the test if(_x>width
left=true; Damn!! therefore the test was never done!


The hard time consuming lessons of a flash beginner...
Thnx a lot guys for your help!
and old and rg,... no fighting ok ? :)

Greetz,

The Muppeteer.
themuppeteer@hotmail.com

Don't eat yellow snow...
 
A good to knowie,

if you ask the size by _root.height and _root.width,
flash gives you the smallest rectangle around all the objects,not the size of the window. so you have to draw a
border rectangle around the rectangle you want to have the size of (héhé). Thats why rgsteward said 'leave the graphic'.
he didn't say why (and I deleted it afterwards and lost half an hour seaching why the ball did not dance across my complete screen...) Greetz,

The Muppeteer.
themuppeteer@hotmail.com

Don't eat yellow snow...
 
Ah ... if only people would do without questioning the wisdom ...

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top