Flasher Archive

[Previous] [Next] - [Index] [Thread Index] - [Previous in Thread] [Next in Thread]


Subject: RE: FLASH: Trouble centering a scaled movie clip
From: Matthijs Koevoets
Date: Tue, 2 Jan 2001 17:41:47 GMT

hi there kevin,

had the same problem some time ago
my solution doesn't require heavy maths but is rather course i suppose
here we go
first i set some variables, they are hard coded boundaries
if the draggable object (the map in your example) has not been scaled then
these are the boundaries within which it is allowed to move.

in my example the map and mask are centered on stage
the width and height of the map would be: 420 (positioned at: top -140,
left -140)
the width and height of the mask: 140
the width and height of the movie: 140

which leaves me with these boundaries:

Set Variable: "maxRight" = "210"
Set Variable: "maxLeft" = "-70"
Set Variable: "maxBottom" = "210"
Set Variable: "maxTop" = "-70"
Set Variable: "startW" = "420"

now i start a loop:
this to get the current width of the map:
Set Variable: "w" = getProperty("../theMap",_width)
next i want to see what the difference is between the original width of the
map and the current width
and divide that by two to get a number that holds the change in position
Set Variable: "shift" = (w - startW) / 2
let me explain
suppose the current width is 430
we know the original width was 420
that leaves us with a difference of 10
which means (since the map is scaling from the center) that 5 pixels have
been added to the left and right
the map will have moved 5 pixels to the left and top
these pixels will need to be added to(/subtracted from) the boundaries: the
map is allowed to move five pixels further than before

next i set two variables to hold the current x and y positions of the map:
Set Variable: "X" = getProperty("../theMap",_x)
Set Variable: "Y" = getProperty("../theMap",_y)
and here finally i start comparing the x and y positions to the updated
boundaries
if the map crosses a boundary it is returned to that boundary:
If (X < maxLeft - shift)
Set Property ("../theMap", X Position) = maxLeft - shift
End If
If (X > maxRight + shift)
Set Property ("../theMap", X Position) = maxRight + shift
End If
If (Y> maxBottom + shift)
Set Property ("../theMap", Y Position) = maxBottom + shift
End If
If (Y < maxTop - shift)
Set Property ("../theMap", Y Position) = maxTop - shift
End If
that's it, keep this looping and you're OK
hope it's all clear. if not, don't hesitate to ask
good luck and happy new year to you and the other flashers

matt


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
flasher is generously supported by...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
flashforward2000 and the Flash(tm) Film Festival
November 27-29, 2000, LONDON, National Film Theatre

Produced by United Digital Artists and lynda.com
-Sponsored by Macromedia, Adobe Systems and Apple Computer
-http://www.flashforward2000.com or UK tel. +44 (0870) 751 1526
Register before November 10 and save �200
http:// www.flashforward2000.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe or change your list settings go to
http://www.chinwag.com/flasher or email helpatchinwag [dot] com


Replies
  FLASH: Trouble centering a scaled movie , Kevin Hays

[Previous] [Next] - [Index] [Thread Index] - [Next in Thread] [Previous in Thread]