|
-
Infinite Loop
Hello,
I have a mouseover "zoom" MC on a background(city). How can I determine the distance between this MC and the _root._x position of the main movie? I would like to zoom in (scale) and have the x position of the main movie smoothly scroll to the x position of the "zoom" MC. My latest attempt is another MC, seperate from "zoom" and "city" on the main timeline with this action...
onClipEvent (enterFrame) {
if (_root.city._xscale==true) {
a = _root._x-_root.city.zoom._x;
_root._x = _root._x+a;
}
}
My math skills need some improvement. I can get the distance between the two _x positons with the variable "a".( I think, still questioning postive and negative values) How can I smoothly scroll the _x postion of the main movie to the _x postion of the "zoom" MC?
Thx in advance!
~GD~
-
Infinite Loop
Someone better at calculations must have an idea how to do this. It seems it shouldn't be as difficult as I'm making it.
Anyone?
-
Hey grvgdr!
Oh dear! After working on your code, I see that the functionality isn't what you require (no mouseover coding, for instance)... owel, the invalid code that you've used is dealt with, and perhaps you can use this to ask more questions! ... I've left your invalid code snippets in place with an explanation as to why they are not valid. BTW this could also be accomplished with localToGlobal, but I haven't used it, opting for 'x upon x' parentage instead:
http://members.shaw.ca/flashmath101/dragScale.swf
http://members.shaw.ca/flashmath101/dragScale.fla
Code:
// main MC
onClipEvent (enterFrame) {
//if (_root.city._xscale==true) { // *** your code - not valid
// _xscale is a percentage value, so perhaps full scale is what you mean
// (although I haven't used it in the code ... it's not being dragged,
// so it will always be at 100% ... it's only acting as conditional to
// fire the rest of the code):
if (_root.city._xscale==100) {
//a = _root._x-_root.city.zoom._x; // *** your code - not valid
// _root._x is always at 0, so to find zoom._x within city relative
// to _root with zoom and city's registration points (0,0) at the
// upper left of their respective graphic areas:
aX = _root.city.zoom._x-_root.city._x+_root.city._width-_root.city.zoom._width;
aY = _root.city.zoom._y-_root.city._y+_root.city._height-_root.city.zoom._height;
// this code is placed on another mc (main MC) that has it's registration
// point at (0.0) of the main stage (_root), and is 100x100 pixels
// so calculated scale and it's pixel count are equal, and is placed on the bottom
// layer so it doesn't hide city when scaled
this._xscale = aX;
this._yscale = aY;
}
}
// zoom MC
onClipEvent (mouseDown) {
if (this.hitTest(_root._xmouse,_root._ymouse)) {
startDrag("");
}
}
onClipEvent (mouseUp) {
stopDrag();
}
Richard
[Edited by Dickee on 11-06-2001 at 02:25 AM]
-
There ... that looks more like what you need ... I've changed the file on the link, and here's the updated code:
Code:
// main MC
onClipEvent (enterFrame) {
if (zoomVar) {
aX = _root.city.zoom._x-_root.city._x+_root.city._width-_root.city.zoom._width;
aY = _root.city.zoom._y-_root.city._y+_root.city._height-_root.city.zoom._height;
this._xscale = aX;
this._yscale = aY;
} else {
this._xscale = 100;
this._yscale = 100;
}
}
// zoom MC
onClipEvent (mouseDown) {
if (this.hitTest(_root._xmouse,_root._ymouse)) {
startDrag("");
}
}
onClipEvent (enterFrame) {
if (this.hitTest(_root._xmouse,_root._ymouse)) {
_root.main.zoomVar = 1;
} else {
_root.main.zoomVar = 0;
}
}
onClipEvent (mouseUp) {
stopDrag();
}
Richard
-
Infinite Loop
Hello,
Thx for the reply. That is an intersting drag code. It has given me some ideas for another project. Thx! It is not quite what I'm trying to do with this.
I would like to create a zoom on mouseover that adjusts the _root._x position of the main movie to the "zoomMC". It needs to smoothly scroll _root._x position to the zoomMC_x position on "zoomin" and return on "zoomout". I can do it by manually setting the x position in the code of the "zoomMC" ...
_root.room._x = _root.room._x-20;
However, What I finally would like to do is to be able to position and call the "zoomMC" to any point with actionscript. A zoom function. Here is the code I am using for the "zoomMC"....
Code:
onClipEvent (enterFrame) {
if ((this.hitTest(_root._xmouse, _root._ymouse, true) == true) && (this._xscale<375) && (_root.room._xscale<375)) {
this._xscale = this._xscale+5;
this._yscale = this._yscale+5;
_root.room._xscale = _root.room._xscale+10;
_root.room._yscale = _root.room._yscale+10;
_root.room._x = _root.room._x-20;
} else if ((!this.hitTest(_root._xmouse, _root._ymouse, true) == true) && (this._xscale>100) && (_root.room._xscale>100)) {
this._xscale = this._xscale-5;
this._yscale = this._yscale-5;
_root.room._xscale = _root.room._xscale-10;
_root.room._yscale = _root.room._yscale-10;
_root.room._x = _root.room._x+20;
}
if (_root.room._xscale>=350) {
_root.room.hiddena.caveentrance.gotoAndPlay("lab");
} else if (_root.room._xscale<=330) {
_root.room.hiddena.caveentrance.gotoAndStop("1");
}
}
Here is a demo of 3 different _x position changes on zoom. I can get it all to work, just got a little ahead of myself and thought maybe I could "dynamically" determine the "zoomMC"._x Then, for example, on mousedown, attatch that MC to wherever the mouse is and zoom accordingly....
http://caveart.tv/scaletest2.swf
Looking at this code, I see the distance between _root.x and zoom.x added to the width of both.Now, I don't need the y as I just want to move along the x on "zoom". I have the "zoom"(scale) code set. How can I tell the Root._x to move the distance between itself and zoom._x on mouseover, and return to original on mouseout "whereever" "zoom._x" may be?
aX = _root.city.zoom._x-_root.city._x+_root.city._width-_root.city.zoom._width;
aY = _root.city.zoom._y-_root.city._y+_root.city._height-_root.city.zoom._height;
P.S. I have been testing a couple different versions of this. I think in the first one I used "city" as the variable instead of "room", as in the example above. They are interchangeable.
Thx again~
~GD~
-
That's a cool app ... you seem to be well on the way! But I still don't get something:
1. I would like to create a zoom on mouseover that adjusts the _root._x position of the main movie ...
2. Looking at this code, I see the distance between _root.x and zoom.x added to the width of both ...
1. There is no way to 'adjust' the _root._x position of the main movie ... it is always '0' ... you can adjust the zoom._x with respect to _root._x, but not vice-versa.
2. Likewise for width, you can't manipulate the _root._width ... it isn't a property ... it can only be changed with the Modify/Movie/ drop-down in the authoring environment, and be referred to with a representative variable ... ie. 'stageWidth = 550'. You can return a value for _root,_width, but it only refers to the total width of the graphics onscreen, not the stage itself.
Am I missing something ... perhaps you have an mc called 'Root' onstage?
Richard
-
Infinite Loop
You are correct. I was misstateing things. I am looking to smoothly scroll from the distance between _root.room._x and _root.zoom._x. Not _root._x. I can determine the distance between these two with....
_root.room._x - _root.zoom._x
(still questioning positive and negative values)
But, how to smoothly scroll from _root.room._x to _root.zoom._x and back on rollout escapes me. With the previous code, I do it manually with an if scale=375
_root.room.x=_root.room._x-20 if scale =100 _root.room.x=_root.room._x+20
I would like to determine a way to code the distance("20") dynamically, so I can position the "zoomMC" anywhere and the root.room._x automatically adjusts.
Thx again for your time. Would a look at the fla help any? Most of the code for it is already here.
Regards
~GD~
-
Please post the .fla ... there's nothing like an example in hand for full comprehension! I need to shut down for the evening, however ... my eyes have gone buggy ... I'll check it out in the morning. Perhaps you'll get some results from another Flasher by then.
Richard
-
Infinite Loop
Hi again,
Sorry I didn't get back to this post last night, but I had enough for one night! Anyway, I am getting closer. Here is the "city" fla. It is the same as the room fla minus alot of "extra" stuff. In the code, "room" is replacable with "city" for this fla, everything else is the same....
http://caveart.tv/scaletest3.fla
K, now what I have gotten closer with is this code( which is not in the "city" fla.......
onClipEvent (enterFrame) {
aX = _root.city.zoom._x-_root.city._x;
if ((this.hitTest(_root._xmouse, _root._ymouse, true) == true) && (this._xscale<150)&&(_root.city._xscale<150)) {
this._xscale = this._xscale+5;
this._yscale = this._yscale+5;
_root.city._xscale = _root.city._xscale+5;
_root.city._yscale = _root.city._yscale+5;
_root.city._x = _root.city._x+aX;
} else if ((!this.hitTest(_root._xmouse, _root._ymouse, true) == true) && (this._xscale>100)&&(_root.city._xscale>75)) {
this._xscale = this._xscale-5;
this._yscale = this._yscale-5;
_root.city._xscale = _root.city._xscale-5;
_root.city._yscale = _root.city._yscale-5;
_root.city._x = _root.city._x-aX;
}
}
It will change the "_x" position on scale in but not scale out and it is instant, instead of a smooth scroll to the new x position. It seems this should be pretty straight forward math. Determining the distance between the two _x positions and smoothly scrolling that distance on zoom in and return to original _x on zoom out. As I said in a previous post, my math skills are not allowing me to figure this out! Any help appreciated!
Thx!
~GD~
-
Infinite Loop
K,
shouldn't this return the "distance" between the _x position of the two MC's...
aX = _root.city.zoom._x-_root.city._x;
Then to change the _x position....
_root.city._x = _root.city._x+aX
Is there a better way to determine the distance between the two MC's and How can I smoothly scroll the "distance" instead of jumping from one to the other?
Thx
~GD~
-
OK ... I tried your posted code (I put it on 'zoom' MC ... I hope that's right!), and instead of adding or subtracting aX to city._x, I introduced 2 'if' conditional increment/decrements for city._x, and placed some textfields onscreen, which shows city moving 50 pixels right on zoom. It works the same for both versions of aX that I included (although aX changes with '-' coding on zoom, but it stays the same with '+' coding).
Hope that helps!
http://members.shaw.ca/flashmath101/...aletest3_2.swf
http://members.shaw.ca/flashmath101/...aletest3_2.fla
Code:
// city.zoom
onClipEvent (enterFrame) {
//aX = _root.city.zoom._x+_root.city._x;
aX = _root.city.zoom._x-_root.city._x;
_root.zoomX = this._x;
_root.zoomY = this._y;
_root.zoomXscale = this._xscale;
_root.zoomYscale = this._yscale;
if ((this.hitTest(_root._xmouse, _root._ymouse, true) == true) && (this._xscale<150)&&(_root.city._xscale<150)) {
this._xscale = this._xscale+5;
this._yscale = this._yscale+5;
_root.city._xscale = _root.city._xscale+5;
_root.city._yscale = _root.city._yscale+5;
if (_root.city._x != _root.city._x+aX) _root.city._x += 5;
} else if ((!this.hitTest(_root._xmouse, _root._ymouse, true) == true) && (this._xscale>100)&&(_root.city._xscale>75)) {
this._xscale = this._xscale-5;
this._yscale = this._yscale-5;
_root.city._xscale = _root.city._xscale-5;
_root.city._yscale = _root.city._yscale-5;
if (_root.city._x-aX != _root.city._x) _root.city._x -= 5;
}
}
// city
onClipEvent (enterFrame) {
_root.cityX = this._x;
_root.cityY = this._y;
_root.cityXscale = this._xscale;
_root.cityYscale = this._yscale;
}
..edit..
_root.city.zoom._x = the position of zoom._x with respect to the parent's registration point (city._x), not to _root._x. You can see this plainly when you place the textfields onstage.
Richard
[Edited by Dickee on 11-06-2001 at 02:27 AM]
-
Well, on an afterthought:
if (_root.city._x != _root.city._x+aX) _root.city._x += 5;
Unless aX==0, this 'if' conditional will aways fire, so it's not really a valid statement ... what's happening though, is an increment/decrement of 5 pixels each enterFrame for city._x while 100 < city._xscale < 150 ... maybe that's all you need though!
Richard
[Edited by Dickee on 08-27-2001 at 06:19 PM]
-
Infinite Loop
I tried your code, but it does not seem to scroll along the _x to the "_zoom._x" position? It also appears to appears to be setting the _x position manually....
"_root.city._x+=5"
Couple other questions, I am only using the zoomMC as a test for when to scale on the cityMC. Is it necessary to have this....
_root.zoomX = this._x;
_root.zoomY = this._y;
_root.zoomXscale = this._xscale;
_root.zoomYscale = this._yscale;
as well as this....
if ((this.hitTest(_root._xmouse, _root._ymouse, true) == true) && (this._xscale<150) && (_root.city._xscale<150)) {
this._xscale = this._xscale+5;
this._yscale = this._yscale+5;
_root.city._xscale = _root.city._xscale+5;
_root.city._yscale = _root.city._yscale+5;
if (_root.city._x != _root.city._x+aX) {
_root.city._x += 5;
}
The hit test and scale are on the zoomMC(small square) It tells city.MC to scale at the same time as zoomMC. In your fla the city._x position moves 50 , but it is because of the scale. ie, hit test..... (this._xscale<150 && this._xscale>100)
In the demo "rooms" I posted, I manually add the _x position with....
_root.city.x=_root.city._x+20 //on the if actions.
and, why the code on the city MC?....
// city
onClipEvent (enterFrame) {
_root.cityX = this._x;
_root.cityY = this._y;
_root.cityXscale = this._xscale;
_root.cityYscale = this._yscale;
}
Really, all I need is to determine a smooth scroll to and from the _root.zoom._x position from _root.city._x, everything else works.
Thx again for your time!
~GD~
-
Hi I'm not real sure what you're trying to do, but I thought I'd throw this in and if it's way off base...just ignore it 
But this gives you a nice smooth zoom, GD...so maybe you can use it in some way...
I put this on the main timeline....
Code:
MovieClip.prototype.zoom = function () {
if (_root.varZoom) {
this._xscale += 2;
this._yscale += 2;
_parent._xscale += 2;
_parent._yscale += 2;
} else if (_root.varZoom == false) {
this._xscale -= 2;
this._yscale -= 2;
_parent._xscale -= 2;
_parent._yscale -= 2;
}
}
...and then on the zoomMC....
Code:
onClipEvent (load) {
startPosX = this._width;
pstartPosX = _parent._width;
endPosX = this._width * 3;
pendPosX = _parent._width * 3;
}
onClipEvent (enterFrame) {
if (this.hitTest(_root._xmouse, _root._ymouse) && this._width<endPosX && _parent._width<pendPosX) {
_root.varZoom = true;
this.zoom();
} else if (!this.hitTest(_root._xmouse, _root._ymouse) && this._width>=startPosX && _parent._width>=pstartPosX) {
_root.varZoom = false;
this.zoom();
}
}
...I only set it for _x to see if it worked...
Hope it will be of some use, GD....
-pigghost-
-
Infinite Loop
Hey pg,
That is pretty much like the scale I'm using, except it is a function. I am trying to adjust the _xposition of the MC as well as scale at the same time. I can do it manually, just got to wondering if I could do it dynamically, so that I could place the MC anywhere and the _x position would adjust automatically. Here it is done manually.....
http://caveart.tv/scaletest2.swf
I set the _x on scale to , forget the exacts, like 30 to the right for one, 20 to the left for another and 10 up for a y test.
Thx for lookin
~GD~
P.S.~ Dickee, that is a very good idea to use the text boxes to measure the change dynamically! Thx!
[Edited by grvdgr on 08-27-2001 at 06:45 PM]
-
Just posting to say that those extra code snippets are just for the textfields' display ... and my last post dealt with the city._x hardcoding and useless 'if conditional!
Nothing new to report.
Richard
-
Here you go, GD...I think I've got it...same prototype, but with a couple of lines added....
Code:
MovieClip.prototype.zoom = function () {
if (_root.varZoom) {
this._xscale += 2;
this._yscale += 2;
_parent._xscale += 2;
_parent._yscale += 2;
_parent._x = _parent._x - this._x/6;
} else if (_root.varZoom == false) {
this._xscale -= 2;
this._yscale -= 2;
_parent._xscale -= 2;
_parent._yscale -= 2;
_parent._x = _parent._x + this._x/6;
}
}
...and on the zoomClip...same as before...
Code:
onClipEvent (load) {
startPosX = this._width;
pstartPosX = _parent._width;
endPosX = this._width*3;
pendPosX = _parent._width*3;
}
onClipEvent (enterFrame) {
if (this.hitTest(_root._xmouse, _root._ymouse) && this._width<endPosX && _parent._width<pendPosX) {
_root.varZoom = true;
this.zoom();
} else if (!this.hitTest(_root._xmouse, _root._ymouse) && this._width>=startPosX && _parent._width>=pstartPosX) {
_root.varZoom = false;
this.zoom();
}
}
...it's pretty smooth unless you hit the edge of the zoomClip and then it stutters a bit...might work better with a button rollOver instead of hitTest...but I didn't really try it...
Hope this is what you were looking for...
-pigghost-
-
Infinite Loop
Hey again pg,
That still offers a straight scroll without an _x position change on the "_root.city". I can get it the way I want by manually setting the position of _root.city._x. Here is the code I am using, what I am looking for is a way to change the "_root.room._x=_root.room._x+20"(or -20)........
Code:
onClipEvent (enterFrame) {
if ((this.hitTest(_root._xmouse, _root._ymouse, true) == true) && (this._xscale<375) && (_root.room._xscale<375)) {
this._xscale = this._xscale+5;
this._yscale = this._yscale+5;
_root.room._xscale = _root.room._xscale+10;
_root.room._yscale = _root.room._yscale+10;
_root.room._x = _root.room._x-20;
} else if ((!this.hitTest(_root._xmouse, _root._ymouse, true) == true) && (this._xscale>100) && (_root.room._xscale>100)) {
this._xscale = this._xscale-5;
this._yscale = this._yscale-5;
_root.room._xscale = _root.room._xscale-10;
_root.room._yscale = _root.room._yscale-10;
_root.room._x = _root.room._x+20;
}
}
Now, instead of manually seting the _x position and using more than one "zoomMC" to scale the cityMC, I would like to determine a way to set the _root.room._x position to automatically.
I have also run into the scale being choppy if you hit the edge of the "zoom.MC" What I do to kind of adjust for that is to increase the scale of the "zomMC", since it will be hidden, it is just a matter of testing the correct scale size so that you wont hit the edges of the "zoomMC", I will deal more with that if I can get it to dynamically update the _x position.
If I can get this figured out, you could call the "zoomMC" in a number of different ways for a nice zoom effect, ie., a button, mouseover, onclipEvent, get timer, lots of ways to use it if it would dynamically update the "_root.room._x", you could position the "zoomMC" dynamically as well, call it where and when you wanted to zoom and have the zoom "center". I can do it all manually, like I said, but got brave and thought this might work dynamically, like a function. I keep looking at pg's fuction zoom, it seems like that is not far off what I want but with a "center" zoom on the "zoomMC" It seems all I need to figure is how to dynamically scroll the distance between "_root.room._x" and "_root.zoomMC._x", so that no matter where "zoomMC" is on the stage, "_root.room._x" will adjust it's _x position to the "zoomMC" on scale in and back to normal on scale out.
Thx again for your time!
~GD~
-
Hey GD!
I just finished making a file for jo999 that is hauntingly similar to yours ... I imagine that his functionality will eventually be to magnify an area of a map, but the scaling and positioning are quite similar to your app. I've use a function called 'FloatTo' for the positioning, and the download and code is on the thread ... check it out, perhaps you could adapt it to yours:
http://www.were-here.com/forums/show...threadid=85883
BTW, after seeing your last post, I'd like to share a little tip with you ... instead of coding like this:
this._xscale = this._xscale+5;
... use an assignment operator to say the same thing (10 lines of code could be altered likewise on that last post):
this._xscale += 5;
Richard
-
Infinite Loop
Thx,
That looks promising! Curious about this....
this.dist_x = Math.round(endx - this._x);
Like I said, my math skills limit me a bit and I am pretty new to actionscript. I have not used many of the math properties. Wouldn't that be similar to .....
aX=_root.room._x - _root.zoom._x
Why the math.round?
Second, Thx for the operator tip!
onClipEvent (enterFrame) {
if ((this.hitTest(_root._xmouse, _root._ymouse, true) == true) && (this._xscale<375) && (_root.room._xscale<375)) {
this._xscale += 5;
this._yscale += 5;
_root.room._xscale += 10;
_root.room._yscale += 10;
_root.room._x = _root.room._x-20;
} else if ((!this.hitTest(_root._xmouse, _root._ymouse, true) == true) && (this._xscale>100) && (_root.room._xscale>100)) {
this._xscale -= 5;
this._yscale -= 5;
_root.room._xscale -= 10;
_root.room._yscale -= 10;
_root.room._x += 20;
}
}
Looks a little cleaner!Still stuck though 
thx
~GD~
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|