• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 564
  • Last Modified:

Actionscript: Dynamic Resizable Movie Clips


In this flash movie I have made a slider which, when you slide it up or down resizes a movie; however, I am finding it impossible to make dynamically selected object s resize.

Basically; I have various windows on the stage. I want each window when selected, to be resizable by the slider.

At present I have programmed it to resize a window referenced as _root.mstage.bone.  The code looks like this...

function slider() {
      _root.mstage.bone._xscale = int(_root.optionz.resize_bar.knob._y+100);
      _root.mstage.bone._yscale = int(_root.optionz.resize_bar.knob._y+100);
}
setInterval(slider,100);

However, I need it to be dynamic and resize a window that has been selected. I wrote the code to look like this....

function slider() {
      var moviename:String = "_root.mstage." +  _root.optionz.windownames
      moviename._xscale = int(_root.optionz.resize_bar.knob._y+100);
      moviename._yscale = int(_root.optionz.resize_bar.knob._y+100);
}
setInterval(slider,100);

The variable "moviename" creates a reference to the object I want the slider to resize.

The first part of the reference is always the same (_root.mstage.)

The part named "windownames" is a dynamic text field that receives the name of the window that has been selected on mouse down.

The output would then work like this..

_root.mstage.window_one._xscale = int(_root.optionz.resize_bar.knob._y+100);
_root.mstage.window_one._yscale = int(_root.optionz.resize_bar.knob._y+100);

or

_root.mstage.window_two._xscale = int(_root.optionz.resize_bar.knob._y+100);
_root.mstage.window_two._yscale = int(_root.optionz.resize_bar.knob._y+100);

However, even thought it looks correct when traced, it doesnt seem to work.

Am I able to make dynamic references? Do dynamic references work with setInterval functions?

The file is at the following URL to view..  www.vision-street.co.uk/dev/vsdev.fla

To find the code, select the movie clip on the _root time line called optionz and then view the code in the layer named Slider Actions

To view the slider when viewing the swf, right click and select Options


Many thanks.

0
INeedHelp
Asked:
INeedHelp
  • 3
  • 2
1 Solution
 
INeedHelpAuthor Commented:
Also, using the below method to make a selected window focus to the front makes other windows move depths. How can I make a selected window come to the front without moving any of the other windows depths?

on (press) {
      x = this._parent.getNextHighestDepth();
      this._parent.swapDepths(x);
}
0
 
victmoCommented:
Hi,

I couldn't open the .fla file you provided, but it seems to me that your having a mistype error.
Your script is not working because your variable "moviename" is a string and you're treating it as if it was a movieclip.
If you want to create a reference to a movieclip dynamically, you can use square brackets. In your case it would look something like this:

var moviereference:MovieClip =  _root.mstage[_root.optionz.windownames];
moviereference._x = someValue;
...

The approach you're using to bring your selected window to the top is correct, you're just having a little "target" error:

on (press) {
      x = this._parent.getNextHighestDepth(); // CORRECT! your getting the objects parent highest depth
      this._parent.swapDepths(x); //INCORRECT! you need to change the current object depth, not its parent's
}

try:

on (press) {
      var d = this._parent.getNextHighestDepth();
      this.swapDepths(d);
}

One last thing, I recommend using a variable to refer to your currently selected window instead of creating a dynamic textfield. For example:

//inside every window...
on(press){
    _root.selectedWindow = this;
}

function slider(){
    moviereference = _root.selectedWindow;
    moviereference._x = someValue;
    .
    .
    .
}

Hope it helps,

Vic
0
 
INeedHelpAuthor Commented:
Thanks the above change works perfectly. Good stuff :o)

The swapDepths metod is a pain though! I dont want to swop them, I just want to assign the selected window with the next highest depth to put it on top without changing any other windows.

If I swop depths on an object that is 6 windows down, it comes to the front but the old window takes its place 6 windows down. I dont want that. I want the previously selected window to stay where it is. After selection, it should be the 2nd highest depth.

Basically, is there a set depth method without having to deal with if statements etc.

Something a little like this...

on (press) {
      this._parent._depth = NextHighestDepth();
}

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
rascalpantsCommented:
you should probably be using  getNextHighestDepth()  within the swapDepths() method...

so the below code would bring "ball" to the highest depth in the root timeline:

ball.swapDepths( _root.getNextHighestDepth() );


hope that helps.


rp
0
 
INeedHelpAuthor Commented:
I had already done that, but no luck...

this._parent.swapDepths(this._parent.getNextHighestDepth()+1);

The problem with swapDepths is just as it says; it swops depths, so if you're clicking a movie at the bottom of the pile it sends the one at the top to the bottom while bringing the bottom one to the front. It doesnt look right.

Surely Actionscript should have a setDepth method?
0
 
rascalpantsCommented:
you are not using it the way I recommended...

ball.swapDepths( _root.getNextHighestDepth() );

the above code will place the ball movieclip at the very top of anything on the root timeline...

the +1 is not needed.

based on how many levels deep within movieclips you have place the button you are clicking, you will need to reference the root of the movieclip that holds all of the buttons...

so if all of the button where in a movieclip named "menu" that was on the main timeline, and you wanted to put that clicked button on top of all of the others, you use this code:

buttonName.swapDepths( menu.getNextHighestDepth() );


this basically is saying...  swap the depths of buttonName with an arbitrary value of the next highest depth available in that movieclip.

so this works the way you want, if implemented correctly...

I try to avoid using this and _parent, because it does not explain enough to anyone and always seems to find scope problems with people.


rp

0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now