I'm loading an external image into a new, empty MovieClip and it isn't scaling to fit the size of the flash player.
| 1 | import flash.MovieClip; |
| 2 | |
| 3 | class 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.
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...
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):
| 1 | var my_mcl : MovieClipLoader = new MovieClipLoader(); |
| 2 | var mclListener : Object = new Object(); |
| 3 | |
| 4 | mclListener.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 | |
| 10 | mclListener.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 | |
| 16 | my_mcl.addListener(mclListener); |
| 17 | my_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.