Hi have a square on the stage that should change in dimensions depending on which button is pressed. This is the code for the buttons:
function setButton() {
for (var i in menuMc) {
if (menuMc*._name.substr(0, 4) == "btn_") {
clip = menuMc*;
// rollOver and rollOut stuff goes here
clip.onRelease = function(){
}}}}CODE]
Is it possible and if yes how to place the different dimensions in an aray and then call them in the on release?
Thanks in advance
you can do 2 kinds off different scaling… using the _width and _height, or using the _xscale and _yscale, i used the scale coz this is easyer for calculations.
the scale gets set by flash itself standart on 100, (100% of the scale)…
so when you need to resize, you just calculate how much % is the new width compared to the old width, and then use that percent for the scale…
now get ur flash open and let get started:
create a square (like 100x100, on the 0,0 coordinates)
then give it the instance name “screen” for example.
then create ur buttons.
this is actually all it needs, now lets get on with the actionscript.
put this on the square
onClipEvent (load) {
// set up dimensions
// Dimensions[2] will return [500, 300]
// Dimensions[2][1] will return 300
Dimensions = [[400, 400], [700, 450], [500, 300], [350, 500]];
// determine the speed in wich the sqaure should resize
// the lower the faster
speed = 5;
// store current width and height for later calculations
width = _width;
height = _height;
}
onClipEvent (enterFrame) {
// get new height, using the currentActive var
// that one is determined by the buttons
newHeight = Dimensions[currentActive][0];
newWidth = Dimensions[currentActive][1];
// check how much percent it must resize
newXscale = newHeight/height*100;
newYscale = newWidth/width*100;
// and then let the _xscale resize to the percent
// ofcourse with a classy ease :P
_xscale += (newXscale-_xscale)/speed;
_yscale += (newYscale-_yscale)/speed;
}
and this on the buttons:
on(release){
_root.screen.currentActive = X
}
with X being the number of the button (you can use this._name and manipulate it to get the number)
I hope you don’t mind that I ask you one more question about this subject? :sigh: I also load external swf’s in the main movie. I do that with the following AS:
function pagina(page) {
showContent(page);
}
function showContent(page) {
var c = this["content_"+page];
for (var i in this) {
if (this*._name.substr(0, 8) == "content_") {
this*._visible = (this*._name.substr(8) == page);
loadingPage = page;
}
}
}
and I call them in the release from the setButton function with:
pagina(this._name.substr(4));
What I would like to accomplish is that the external swf’s only load when the square is in place (I mean after the movement as made before is done.
[color=red]preloader._visible = false[/color][color=red];
[/color] abc = _root.createEmptyMovieClip("temp", 1000);
abc.onEnterFrame = function() {
t = c.getBytesTotal();
l = c.getBytesLoaded();
per = Math.round(l/t*100);
if (t == l && t != 0) {
[color=red]if (klaar) {[/color]
preloader.percent = "";
preloader._visible = true;
delete this.onEnterFrame;
}
}
Is this what you ment.
On last one! Suppose I want to control to seperate squares on the stage with different dimentions. Do I have to write another proto or can I include it in the excisting one.
Almost you have preloader._visible =false; at the top, shouldn’t that be holder (the mc you load in)? The same for after the if statement preloader._visible = true;?
For your other question, it’s a prototype so it will work for every MovieClip. Target it as
yourmc.easeTo[250,250];
and “yourmc” will ease to a square with dimensions 250 width/height. Or get the values from an array like RvGate and I showed you.
Hope this will help:)
I see the stupid mistake of the preloader :hr: Thanks a lot.
About the second question. I not only change the square in width and height, but now also in x and y position. So then it looks to me impossible to get those dimensions from the same Array! Or am I wrong in that?
LOL, I see my stupid mistake [size=1](at least, I hope)[/size]
Hope I get you right now, you want to change width/height and x/y?
Then you can add the _x/_y properties in the prototype and in the array.
for the proto eg:
The part with the tarX and tarY I figured out already, but the question is about having two squares on the stage I want to control mainSquare and subSquare. When I use your function part [color=red](tarX, tarY, tarW, tarH) [/color]as example
When btn_home is pressed only mainSquare should be on the stage with the following dimensions [color=red](125, 125, 600, 400)[/color] [size=1][color=red]Note: registrationpoint top left corner[/color][/size]
[color=black]Here subSquare is of stage [/color][color=red](-600, 125, 0, 0)[/color]
[color=black][/color]
[color=black]When btn_about is pressed both squares should be on stage[/color]
so I don’t think it is possibe to get de dimensions for both squares from the same array. I think I need to make a second array with the demesions for subSquare, but I don’t know how to combine two arrays :*( with the one prototype I have :hr:
I normaly would say you are absolutely right, but I attached only an example zip because the zip from the original was to heavy to attach, at least that was the message I got when I tried it. In the original Fla I have 8 buttons and with the loop I control also the over, out and release state (new Color), plus there are not only the two squares I would like to control in the final project, but also the menu it self, 4 lines the logo etc. So when I know how to handle the dimensions for the two squares I think I can fugure out how to handle the other objects. Do you understand?