Dynamic image resizing
- liam
-
liam
- Member since: Dec. 11, 2004
- Offline.
-
- Send Private Message
- Browse All Posts (14,243)
- Block
-
- Forum Stats
- Member
- Level 22
- Blank Slate
I was bored the other day and did this, it's pretty cool and might be useful.. somehow :P
Anyway, make a movie clip in the library with something inside that will be resizable. Make this image, or whatever it is inside the MC, 740.0px wide and 590.0px high [THAT WAS IMPORTANT!!]. Right click on the MC inside the library and goto Linkage, click export for actionscript and use 'image' as the identifier.
Now, goto the main timeline and paste these actions on the frames actionsc panel:
var1 = 0;
_root.createEmptyMovieClip("box", 1);
onMouseDown = function () {
box.moveTo(_xmouse, _ymouse);
var1 = 1;
curX = _xmouse;
curY = _ymouse;
removeMovieClip("image");
duplicateMovieClip("box", "box2", 3);
};
onMouseUp = function () {
var1 = 0;
};
onEnterFrame = function () {
duplicateMovieClip("box", "box2", 3);
box2.lineStyle(2, 0x000000, 100);
if (var1 == 1) {
length1 = curX-_root._xmouse;
height1 = curY-_root._ymouse;
box2.lineTo(_xmouse, curY);
box2.lineTo(_xmouse, _ymouse);
box2.lineTo(curX, _ymouse);
box2.lineTo(curX, curY);
attachMovie("image", "image", 2);
image._x = curX;
image._y = curY;
image._xscale = -length1/7.4;
image._yscale = -height1/5.9;
}
};
Now test the movie (ctrl+enter) and drag a square using your mouse.
Sup, bitches :)
- Redshift
-
Redshift
- Member since: Feb. 12, 2005
- Offline.
-
- Forum Stats
- Member
- Level 15
- Programmer
#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}
- Denvish
-
Denvish
- Member since: Apr. 25, 2003
- Offline.
-
- Send Private Message
- Browse All Posts (15,977)
- Block
-
- Forum Stats
- Member
- Level 46
- Blank Slate
That's pretty funky.
Here's a challenge: make it so that it will loadMovie external images from the same folder as the fla, get their dimensions, and adjust accordingly (the 740x590 thing is limiting the code).
I don't even know if it's possible, but it would be a great thing for websites.
- liam
-
liam
- Member since: Dec. 11, 2004
- Offline.
-
- Send Private Message
- Browse All Posts (14,243)
- Block
-
- Forum Stats
- Member
- Level 22
- Blank Slate
At 7/22/05 07:20 PM, Denvish wrote: Here's a challenge: make it so that it will loadMovie external images from the same folder as the fla, get their dimensions, and adjust accordingly
I'll see what I can do, gives me something to spend time on :)
(the 740x590 thing is limiting the code).
Yeah, I know that.. I could change it but I would've had to change the _x and _y of the attached movie.. I should do it so it knows what to times by itself, so yeah I'll try and fix that :P
Sup, bitches :)
- Inglor
-
Inglor
- Member since: Jan. 26, 2003
- Offline.
-
- Send Private Message
- Browse All Posts (10,869)
- Block
-
- Forum Stats
- Member
- Level 17
- Blank Slate
- liam
-
liam
- Member since: Dec. 11, 2004
- Offline.
-
- Send Private Message
- Browse All Posts (14,243)
- Block
-
- Forum Stats
- Member
- Level 22
- Blank Slate
I just made this, it's the same thing except you upload your own image.. problem is that it doesn't resize the image to fit the box, so it's not perfect but it still works. If anyone could fix that problem it would be great, I'm sure it's possible and it's just that I haven't spent enough time on it but anyway, here it is.
Step 1 - Make an input textbox and instance name it 'loadImg' (thats load img, but capital I and no space).
Step 2 - Drag a Loader component on stage, give it an instance of 'loadEr'
Step 3 - Make a button and put these actions on it:
on (release) {
_root.loadEr.contentPath = _root.loadImg.text;
}
Step 4- Put this code on the stage:
var var1:Number = 0;
_root.createEmptyMovieClip("box", 1);
onMouseDown = function () {
box.moveTo(_xmouse, _ymouse);
var1 = 1;
curX = _xmouse;
curY = _ymouse;
duplicateMovieClip("box", "box2", 3);
};
onMouseUp = function () {
var1 = 0;
};
onEnterFrame = function () {
duplicateMovieClip("box", "box2", 3);
box2.lineStyle(2, 0x000000, 100);
if (var1 == 1) {
length1 = curX-_root._xmouse;
height1 = curY-_root._ymouse;
box2.lineTo(_xmouse, curY);
box2.lineTo(_xmouse, _ymouse);
box2.lineTo(curX, _ymouse);
box2.lineTo(curX, curY);
loadEr._x = curX;
loadEr._y = curY;
loadEr._xscale = -length1;
loadEr._yscale = -height1;
}
};
Example: link.
Notes:
* Only works with jpeg and swf.
* Works best with square images.
* Don't use without crediting me.
Sup, bitches :)
- liam
-
liam
- Member since: Dec. 11, 2004
- Offline.
-
- Send Private Message
- Browse All Posts (14,243)
- Block
-
- Forum Stats
- Member
- Level 22
- Blank Slate
At 8/26/05 09:13 AM, SpamBurger wrote: This could be very useful for drawing pads where the user can draw a quick sqaure. Is it possible to make it a circle instead of a square?
Yes, but this isn't anything to do with the square.. it's the picture that loads inside it =P
Sup, bitches :)
- Rustygames
-
Rustygames
- Member since: May. 7, 2005
- Offline.
-
- Forum Stats
- Member
- Level 19
- Programmer
- Matt, Rustyarcade.com
- Rustygames
-
Rustygames
- Member since: May. 7, 2005
- Offline.
-
- Forum Stats
- Member
- Level 19
- Programmer
At 8/26/05 09:46 AM, Ninja-Chicken wrote: I cant even get it to work
Yeah that doesnt even work you havnt loaded anything
- Matt, Rustyarcade.com
- liam
-
liam
- Member since: Dec. 11, 2004
- Offline.
-
- Send Private Message
- Browse All Posts (14,243)
- Block
-
- Forum Stats
- Member
- Level 22
- Blank Slate
At 8/26/05 09:49 AM, Ninja-Chicken wrote: Yeah that doesnt even work you havnt loaded anything
Who hasn't loaded anything?
If it doesn't work, try refreshing the page.
Sup, bitches :)
- MouthWindow
-
MouthWindow
- Member since: Dec. 4, 2004
- Offline.
-
- Forum Stats
- Member
- Level 08
- Blank Slate
this is all the more reason for me to learn AS properly lol
- Rustygames
-
Rustygames
- Member since: May. 7, 2005
- Offline.
-
- Forum Stats
- Member
- Level 19
- Programmer
At 8/26/05 09:51 AM, -liam- wrote:At 8/26/05 09:49 AM, Ninja-Chicken wrote: Yeah that doesnt even work you havnt loaded anythingWho hasn't loaded anything?
If it doesn't work, try refreshing the page.
Dude your code doesnt load anything
- Matt, Rustyarcade.com
- liam
-
liam
- Member since: Dec. 11, 2004
- Offline.
-
- Send Private Message
- Browse All Posts (14,243)
- Block
-
- Forum Stats
- Member
- Level 22
- Blank Slate
At 8/26/05 10:00 AM, Ninja-Chicken wrote: Dude your code doesnt load anything
Are you reading the first post or the sixth?
Sup, bitches :)
- Rustygames
-
Rustygames
- Member since: May. 7, 2005
- Offline.
-
- Forum Stats
- Member
- Level 19
- Programmer
At 8/26/05 10:06 AM, -liam- wrote:At 8/26/05 10:00 AM, Ninja-Chicken wrote: Dude your code doesnt load anythingAre you reading the first post or the sixth?
sixth
The image doesnt load onto the stage (from the path I give it)
- Matt, Rustyarcade.com
- liam
-
liam
- Member since: Dec. 11, 2004
- Offline.
-
- Send Private Message
- Browse All Posts (14,243)
- Block
-
- Forum Stats
- Member
- Level 22
- Blank Slate
At 8/26/05 10:07 AM, Ninja-Chicken wrote: The image doesnt load onto the stage (from the path I give it)
Try giving it a different path then, try different pictures.
Sup, bitches :)
- Ninja-chicken
-
Ninja-chicken
- Member since: Aug. 8, 2005
- Offline.
-
- Forum Stats
- Member
- Level 04
- Blank Slate
At 8/26/05 10:10 AM, -liam- wrote:At 8/26/05 10:07 AM, Ninja-Chicken wrote: The image doesnt load onto the stage (from the path I give it)Try giving it a different path then, try different pictures.
No the code is wrong. There is no loadMovie
- liam
-
liam
- Member since: Dec. 11, 2004
- Offline.
-
- Send Private Message
- Browse All Posts (14,243)
- Block
-
- Forum Stats
- Member
- Level 22
- Blank Slate
At 8/26/05 10:12 AM, Ninjachickensson wrote: No the code is wrong. There is no loadMovie
There isn't supposed to be any loadMovie, I haven't use that.
Have you even tried dragging the mouse after loading the image? That's what you're supposed to do, and it does work.
Sup, bitches :)
- Ninja-chicken
-
Ninja-chicken
- Member since: Aug. 8, 2005
- Offline.
-
- Forum Stats
- Member
- Level 04
- Blank Slate
At 8/26/05 10:12 AM, Ninjachickensson wrote:At 8/26/05 10:10 AM, -liam- wrote:No the code is wrong. There is no loadMovieAt 8/26/05 10:07 AM, Ninja-Chicken wrote: The image doesnt load onto the stage (from the path I give it)Try giving it a different path then, try different pictures.
Shit no sorry. Yeah it seems to work on internet images but not local files
Weird
- Glaiel-Gamer
-
Glaiel-Gamer
- Member since: Dec. 28, 2004
- Offline.
-
- Forum Stats
- Member
- Level 28
- Game Developer
- liam
-
liam
- Member since: Dec. 11, 2004
- Offline.
-
- Send Private Message
- Browse All Posts (14,243)
- Block
-
- Forum Stats
- Member
- Level 22
- Blank Slate
At 8/26/05 11:58 AM, Glaiel_Gamer wrote: it has to be a .jpg
Or a .swf, but that can mess up sometimes.
Sup, bitches :)
- 4as
-
4as
- Member since: Nov. 18, 2004
- Offline.
-
- Forum Stats
- Member
- Level 20
- Blank Slate
I think, here's a little bit better code:
_root.pressed = false;
_root.createEmptyMovieClip("imaged", 1);
_root.imaged.createEmptyMovieClip("inImage
", 0);
_root.createTextField("texted", 0, 10, 10, 300, 20);
_root.texted.border = true;
_root.iWidth = 0;
_root.iHeight = 0;
_root.texted.borderColor = 0x000000;
_root.texted.textColor = 0x000000;
_root.texted.type = "input";
_root.onKeyDown = function() {
if (Key.isDown(Key.ENTER)) {
loadMovie(_root.texted.text, _root.imaged.inImage);
}
};
Key.addListener(_root);
_root.onMouseDown = function() {
_root.iWidth = _root.imaged.inImage._width;
_root.iHeight = _root.imaged.inImage._height;
_root.pressed = true;
_root.imaged._x = _root._xmouse;
_root.imaged._y = _root._ymouse;
_root.imaged._xscale = 100*((_root._xmouse-_root.imaged._x)/_root
.iWidth);
_root.imaged._yscale = 100*((_root._ymouse-_root.imaged._y)/_root
.iHeight);
};
_root.onMouseMove = function() {
if (_root.pressed) {
_root.imaged._xscale = 100*((_root._xmouse-_root.imaged._x)/_root
.iWidth);
_root.imaged._yscale = 100*((_root._ymouse-_root.imaged._y)/_root
.iHeight);
}
};
_root.onMouseUp = function() {
_root.pressed = false;
};
Just copy and paste into a movie.
It loades external image (SWF or JPG).
Just type in a path to image, press enter and enjoy.
I didnt bother with drawing borders of image...


