Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [ActionScript] haXe: Scaling External Image to Fit?

This thread is locked; no one can reply to it. rss feed Print
[ActionScript] haXe: Scaling External Image to Fit?
Billybob
Member #3,136
January 2003

I'm loading an external image into a new, empty MovieClip and it isn't scaling to fit the size of the flash player.

1import flash.MovieClip;
2 
3class Test {
4 private static var app:Test;
5 private static var mc:flash.MovieClip;
6 
7 public function new() {
8 flash.Stage.scaleMode = "noScale";
9 flash.Stage.align = "TL";
10
11 mc = flash.Lib.current;
12 var tmc = mc.createEmptyMovieClip("s1_", mc.getNextHighestDepth());
13 tmc.loadMovie("sunflower.jpg");
14
15 tmc._x = flash.Stage.width/2;
16 tmc._y = flash.Stage.height/2;
17 tmc._width = flash.Stage.width;
18 tmc._height = flash.Stage.height;
19
20 trace(tmc._xscale);
21 trace(tmc._yscale);
22
23 tmc._xscale = 0.5;
24 tmc._yscale = 0.5;
25 }
26 public static function main() {
27 flash.Lib.setErrorHandler(myHandler);
28 app = new Test();
29 }
30
31 static function myHandler(msg : String, stack : Array<String> ) {
32 trace("Error : "+msg);
33 }
34}

I've tried and tried to get it to scale by setting xscale and width and so forth, but every time I do the image just disappears. Any ideas?

Thank you.

EDIT: Setting the scale works (apparently it's 50 == 50% instead of 0.5), but I don't know the size of the image to begin with so I can't scale it properly.

bamccaig
Member #7,536
July 2006
avatar

Why do you need to know the size of the image to scale it? :-/ If there is a property that automatically scales the image then shouldn't it work to indicate the same scale for both axises (is axises a word? I don't know)? :-/

** EDIT **

Without knowing exactly what I'm looking for I found this post* on another forum that claims to know how to get image dimensions... :-/ I don't know if haXe is different from Flash's ActionScript or not nor which versions of ActionScript this is supported in...

SteveMania@forums.macrumors.com said:

I know this is an old thread, but I am sick of reading posts that i personally want answers for and there not being one after all of that reading! Below is how you should load images and gain access to their height/width and so on... The answer is onLoadInit(); onLoadComplete will not work because all of the variables and things are not initialized until the onLoadInit(); Hope this saves someone some time!

Use the MovieClipLoader object (with a Listener):

1var my_mcl : MovieClipLoader = new MovieClipLoader();
2var mclListener : Object = new Object();
3 
4mclListener.onLoadProgress = function(target_mc:MovieClip, numBytesLoaded:Number, numBytesTotal:Number):Void
5{
6 var pctLoaded:Number = Math.ceil(100*(numBytesLoaded/numBytesTotal));
7 // This will get you the percent amount loaded for use in a preloader, etc...
8};
9 
10mclListener.onLoadInit = function(mc:MovieClip):Void
11{
12 // This is the method that will return the proper values for height/width
13 trace("LoadInit Rules! " + mc._width);
14}
15 
16my_mcl.addListener(mclListener);
17my_mcl.loadClip(imageVariable, MovieClipToLoadImageInto);

- Source

** EDIT **

I didn't get a chance to read through it, but this (Flash MX) or this (Flash MX 2004/8) might help as well.

* I formatted the code for readability and prettiness.

Go to: