This content has been marked as final. Show 22 replies
For the browse box, I would use BuddyAPI's baGetFilename() which will
pull up that dialog box and tell you which file the user chose.
To shrink the image into a given area, you just need to scale the .rect
of the sprite and make sure you keep the aspect ratio the same as that
of the original member.
Thanks for the quick reply. Are there any tutorials or help documents on how to work with these properties you mentioned?
The help docs that come with BuddyAPI do a good job of explaining how to
use it. And there isn't much to scaling a rect of a sprite...
You can simply set the rect to go into a certain area, like
Which will put it in a 100 x 100 box in the top corner. Or course you
will want to get the aspect ratio of the image you are importing
(member.height and member.width) and scale it proportionally.
Cool. I will play with it and post something here when I get it to work. Thanks for pointing me in the right direction Mike.
I was able to get an imported image to be re-sized to another size automatically. The question is, how can I make it retain proportions. The image I tested is portrait and the one I used as my safe area is landscape. This is the code I used:
on exitFrame me
sprite(2).rect = sprite(1).rect
I know it is way to simple, but what do I need to add so that sprite(2) re-sizes and keeps proportions?
Thanks for the link.
How and where would I use something like this? My previous code I was adding in a frame script. I think this would go on the member (place holder for member) it self?
At any point after the program has brought in the image, run this line
Replace YOURMEMBERNAME with the name of the image member
Replace the 1st 100 with the max width
Replace the 2nd 100 with the max height
I get a "Handler not defined" error. I think I am confusing where do I need to add the script from mediamacross.com and where to add "rescale(member("YOURMEMBERNAME"),100,100)"
I got it. I figure out where the code needed to go.
Ok...I got it work, but it only works once! It re-sizes the image when I run it the first time but...
If I run it again it gives me a prop error on the first line script line:
Script error: property not found
membRef.useAplha = FALSE...etc
I used the -- to ignore this line, but the it gives me the same error for the following line after that line...
Above the line where the error occurs, put this
What does that put in the message window?
Well...it ignores it, and gives me the same error the second time around. Now, I see that:
1.It works the first time I run it.
2.If I run it again, and the image is already imported, then it gives me the error.
When I run it the first time, for some reason the member's name is clear, the cast member shows no name, weird.
When you say it ignores it, do you mean that it does not put anything in
the message window? If that is the case then you probably have the
script in twice, and it is running the one that you did not add that
line to... or something like that.
If you added that line where I told you to, it should always put
something in the message window, and the first time it is run, that
something is what it needs.... the second time it is run, when it
crashes, that something will be the incorrect value.
I apologize, I thought you meant the message window where I get the error. I place the code on the Window>message window and it gives me this:
== Movie: C:\Documents and Settings\Rafa\Desktop\Director_resize image\re_size2.dir Frame: 1 Script: (member 0 of castLib 0) Handler:
--> _movie.traceScript = 0
other times it gives me this:
-- (member 5 of castLib 1)
Here is the code I am using, I do not believe I am adding anything twice (besides whatever was on the original line of code)
Instead of putting the whole rescale code in your frame script, make it
a movie script. Remove all the on rescale.... stuff that you copied
from mediamacros and make a new movie script. Make sure it is a movie
script. Paste the handler in there.
So you will have 2 scripts. One is a behaviour that looks like this:
on exitframe me
the other script is a movie script that is exactly what you have for the
on rescale... handler
Then, I think it will work as expected. I am working under the
assumption that the original image in the score is "man walking" and the
"MTPLogo" is the one that the user selected.
Also, you may not want to put that code on exitFrame. Unless it only
appears on a single frame... If that script is running 15 times a
second, and it is constantly rescaling the image, then it will slow your
program down a lot. It is best to put the rescale line of code
immediately after whantever code you have for bringing in the new image
and setting the image on the stage. That way it only runs once and won't
slow you down.
I made the changes you suggested. I added the rescale code on a movie script by itself. The image is shown on a single frame, I do not have multiple sections on the project where this image will show, only one. Now I get the error the first time I run it, but it does resize the image and then inmediatley gives me the error "Script error:Property not found
membRef.useAlpha=FALSE--in director MX/winXP bmp's standard useAlpha=TRUE" when it reaches the "rescale(member("man walking"),100,100)" command.
Now I tried placing the whole script on a movie script, including "rescale(member("man walking"),100,100)" and I don't get the error the first time I run it, only the second time around. I think it has something to do with the member's name being changed after it is rescaled, why do you think it changes the member's name?..well, it doesn't change it, it clears it, member has no name after it is rescaled.
This code is apparently meant to use the member number not name, so it
is not properly renaming things after it does the conversion. Try this
one instead which is edited slightly to make sure the name is the same.
Put it in its own movie script and call it from your behaviour.
on rescale membRef,maxW,maxH
membRef.useAlpha=FALSE--in director MX/winXP bmp's standard
repeat while wide>maxW or high>maxH
if wide>maxW then
if high>maxH then
k=new(#bitmap,membRef)--just one time
The rescale code is in a movie script and the behavior is in a frame script.
Why would the original code deal with member numbers? Wouldn't that make it harder to identify specific members? Or is it more advanced to work with members that way?
I didn't write the code, so I can't speak to why the author did things
the way they did... but it may just be that it was written for an older
version of Director. But what the script does save the image, delete
the member, then it makes a new member in the place where the old one
was and puts the scaled image into that. Perhaps not the way I would
have gone about it, but it works. Apart from the naming thing. If you
fed it the oldschool
member(3) of castlib 1
then it would have worked as expected.
Ok, so it just an older way of accomplishing the same thing. I guess I am spoiled, I started using Director with MX...
Mike, thanks for all your help ( and for all the other times you have helped me before.) This little feature makes my project a lot more user friendly.