header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
Catalin Dumitru
Points:0
Posts:0

9/6/2010 5:00:43 AM

Title: Passing a reference through a function?


I have a strange problem when I try to create a function that loads an image from file. The reference to the bitmap data that I want to put the loaded image into, doesn't seem to be correctly remembered when flash calls the imageLoaded function. If I add the bitmapData variable to the stage in that function, it displays the image correctly. But, if in the same function, I add the variable which is being passed to the stage, I just get an empty texture. How can I return correctly the bitmap data that is being loaded?


		private function _LoadTexture(path : String, bitmapData : BitmapData)
		{
			var imageLoader : Loader = new Loader();
			imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
			imageLoader.load(new URLRequest (path));
			this._objectsLoading++;

			function imageLoaded(event : Event)
			{
				bitmapData = Bitmap(imageLoader.content).bitmapData;
				_FinishedLoading();
			}
		}




1
Andrid
Points: 720
Posts:0
9/6/2010 5:10:45 AM



loading image is asynchronous process. Which means that your function execution is finished before the image is loaded . so it will always return you empty texture. Any function that is making external url calls can never return you externally loaded data, because function will not stop and wait for image to load and then return you data, but it will just return you the data immediately which would be empty.

2
Catalin Dumitru
Points: 0
Posts:0
9/6/2010 5:19:26 AM



I can see that, but doing some more experimenting, I found that returning the bitmap data like I did...



bitmapData = Bitmap(imageLoader.content).bitmapData; 



..doesn't work, but using the copyPixels function works.




var temp : BitmapData = Bitmap(imageLoader.content).bitmapData;
bitmapData.copyPixels(temp , temp.rect, new Point(0,0));

Which is strange because the reference is stored, and can be used. I think that my problem was that I was changing where the bitmapData reference was pointing, and not the content itself if that makes any sense.

3
Rex
Points: 1280
Posts:0
9/6/2010 5:44:51 AM



strange ,maybe this should also work

bitmapData = imageLoader.content as BitmapData ;




4
Catalin Dumitru
Points: 0
Posts:0
9/6/2010 5:51:11 AM






bitmapData = imageLoader.content as BitmapData ; 

Nope... the only way that I found is to copy pixel by pixel, which is not very optimized, but at least it works.


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 5+4 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions