3 Replies - 7232 Views - Last Post: 07 August 2009 - 09:36 PM

#1 JustLearning  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 41
  • Joined: 07-August 09

get and change MovieClip heigt and width

Post icon  Posted 07 August 2009 - 09:51 AM

Is there a code that I can use that will get the height and/or width of MovieClip that is in my library, so that if I decide to change the size of the MovieClip later these numbers will be automatically updated in my script?

Also, when the actionscript places an instance of a MovieClip on the stage, is it possible to resize the instance?
I am using _root.attachMovie to place the instances of my MovieClip from the library to the stage.

I am using actionscript 2.0. If necessary, I can explain more details and show how I want to use this in my code.

Thank you!

This post has been edited by JustLearning: 07 August 2009 - 11:21 AM


Is This A Good Question/Topic? 0
  • +

Replies To: get and change MovieClip heigt and width

#2 gregwhitworth  Icon User is offline

  • Tired.
  • member icon

Reputation: 216
  • View blog
  • Posts: 1,602
  • Joined: 20-January 09

Re: get and change MovieClip heigt and width

Posted 07 August 2009 - 02:21 PM

Sure -

Place this in the frame actions:
mcHeight = mcName._height;
mcWidth = mcName._width;



Then (since using as2) place this on the button:
on (release) {
_root.mcName._xscale=110;
_root.mcName._yscale=110;
}



The first part will give you the variables of the width and height but aren't necassary for scaling, because flash already knows the information. If you want to- you can use the _width and _height in place of _xscale and _yscale.

--

Greg



}
Was This Post Helpful? 0
  • +
  • -

#3 JustLearning  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 41
  • Joined: 07-August 09

Re: get and change MovieClip heigt and width

Posted 07 August 2009 - 09:06 PM

Thank you, but I do not understand how to use this code. To try to figure it out, I made a movieclip in my library called mcName and used the following code to see if it gave me the correct height. Instead of giving me the movieclip height, it said "undefined" Will you please explain why this is not working for me?

mcHeight = mcName._height;
trace(mcHeight);



Also, in the above code, I am not clear about whether I am referring to the movieclip in the library or an instance of the movieclip. I would like to be able to refer to an instance of the movieclip, but I was just trying to refer to the library (maybe this is not possible?).

The following script is what I am actually working on. I am just trying to learn how to place instances of movieclips on to the stage. I have a movieclip in my library called "block". For var x, I would like to replace 50 with the code that gets the width of the movieclip. For var y, I would like to replace 30 with the code that gets the height of the movieclip. Oh, but I would like only to have help with the above problem and to figure out how to use it in my code (below) on my own. Thanks!

function randomlocation(min:Number, max:Number):Number {
	var randomNumber:Number = Math.floor(Math.random()*(max-min+1))+min;
	return randomNumber;
}

for (var i = 0; i < 50; i++)
{ 
var randomNumberX = randomlocation(0, 800);
var x = Math.floor(randomNumberX / 50) * 50; 

var randomNumberY = randomlocation(0, 250);
var y = Math.floor(randomNumberY / 30) * 30;

_root.attachMovie("block", "block"+i, i, {_x:x,_y:y});

}



Thanks again for your help!

This post has been edited by JustLearning: 07 August 2009 - 09:20 PM

Was This Post Helpful? 0
  • +
  • -

#4 gregwhitworth  Icon User is offline

  • Tired.
  • member icon

Reputation: 216
  • View blog
  • Posts: 1,602
  • Joined: 20-January 09

Re: get and change MovieClip heigt and width

Posted 07 August 2009 - 09:36 PM

mcHeight = mcName._height;
trace(mcHeight);



Yeah it would be undefined unless you have a movie clip named mcName, do you?

mcName is the name of the movie clip, there I go assuming again.

So if your movie clip is sharkAttack - your code would be:

mcHeight = sharkAttack._height;
trace(mcHeight);



And make sure to go through the movie outline correctly, and what I mean by that is if this movie is within another movie and you are calling this script from the main stage you need to do:

anotherMovieClipthatHolds.sharkAttack._height;

or

_root.anotherMovieClipthatHolds.sharkAttack._height;



The last one is like doing a direct path in HTML versus a relative path:

RELATIVE:
../images/logo.jpg

vs

DIRECT
http://www.domain.com/images/logo.jpg




Quote

Oh, but I would like only to have help with the above problem and to figure out how to use it in my code (below) on my own. Thanks!


And that's how you learn, props to you man for not wanting a hand out, who knows you could end with a career as a flash developer. You should stick around DIC - we could use more honest hard working people.

--

Greg
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1