Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > Extensions and Plugins > JSFL - Extending Flash

Reply
 
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
Old 08-16-2005, 10:48 AM   #1
craigdsp
Registered User
 
Join Date: Jul 2005
Posts: 9
Default Moving a selection

i'm trying to write a little command that will move my selection to whole pixels.

i though originally that i would be able to write it so that i can select a bunch of things and have jsfl loop through them and move each one onto whole pixels. this failed miserablly so i'm now attempting to just get the selection moved onto a whole pixel which works with a 0.1% margin of error, which obviously dosen't work. grr it's winding me up.

ActionScript Code:
dom = fl.getDocumentDOM(); rect = dom.getSelectionRect(); l = (Math.ceil(rect.left) - rect.left); t = (Math.ceil(rect.top) - rect.top); alert(l) alert(t) dom.moveSelectionBy({x:l, y:t});
craigdsp is offline   Reply With Quote
Old 08-16-2005, 11:00 AM   #2
craigdsp
Registered User
 
Join Date: Jul 2005
Posts: 9
Default

ok so if i switch from using Math.ceil() to using Math.floor() it works , observe:

ActionScript Code:
dom = fl.getDocumentDOM(); rect = dom.getSelectionRect(); l = (Math.floor(rect.left) - rect.left); t = (Math.floor(rect.top) - rect.top); dom.moveSelectionBy({x:l, y:t});

however this isn't truley moving it to the nearest pixel, it's moving it to the lowest whole pixel. not good. how can i make it behave like Math.round() without the errors??
craigdsp is offline   Reply With Quote
Old 08-16-2005, 11:17 AM   #3
craigdsp
Registered User
 
Join Date: Jul 2005
Posts: 9
Default

ok so this is working like 99% :

ActionScript Code:
dom = fl.getDocumentDOM(); rect = dom.getSelectionRect(); alert(rect.left); alert(Math.round(rect.left)) alert(rect.top); alert(Math.round(rect.top)) if (rect.left < Math.round(rect.left)) {     l = (Math.floor(rect.left) - rect.left)+1; } else {     l = (Math.floor(rect.left) - rect.left); } if (rect.top < Math.round(rect.top)) {     t = (Math.floor(rect.top) - rect.top)+1; } else {     t = (Math.floor(rect.top) - rect.top); } dom.moveSelectionBy({x:l, y:t});

sometimes however it will land on either xxx.1 or xxx.9 positions, this tends to occur when the original begins xxx.049xxxxxxx obviously where i am adding 1 to counter the Math.floor() when needed i am in fact adding 1.049 am i right in thinking that?? is it just that the Math class can't handle these numbers or what???
craigdsp is offline   Reply With Quote
Old 08-16-2005, 01:00 PM   #4
hangalot
lala
 
hangalot's Avatar
 
Join Date: Feb 2002
Location: on the road
Posts: 2,859
Default

i think this is a floting point math issue. what you can try is to execute two math.round's on it... a hack but it might work
__________________
oi poloi
http://www.memorphic.com/news/
hangalot is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:26 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.
You Rated this Thread: