You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by CodeGirl <Mi...@yahoo.com> on 2016/08/26 13:23:06 UTC

Loading JPG bitmapdata. Something like Embed but at runtime

If I have the image hard coded into my class, I do not get any errors and my
3D image loads.

[Embed("panels/BrownPanel.jpg")]
private static const BROWNPANEL:Class;

this.panelTexture = [new BROWNPANEL().bitmapData];

Guessing the bitmapdata is loaded at compile time.

however, when I try to load the image at run time, I keep getting an error
saying the bitmapData needs to be non-null.  
I have tried loaders of all kinds and I keep getting errors as if the
bitmapdata is not loaded yet at runtime.  I have tried using Image,
BitmapImage, Bitmap.  Still no joy.

I could post code on my loaders but I have tried so many variations. Ones
that supposedly work.

Here is the base classes code where the error is happening in my Shape3D.as
Class.
			graphics.clear();
			//draw
			for (i = 0; i < len; i++) {
				graphics.beginFill(colors[i]);
				graphics.drawTriangles(vertices, indices[i], null,
TriangleCulling.NEGATIVE);
				graphics.endFill();
				graphics.beginBitmapFill(texture[i], null, true, true);
				graphics.drawTriangles(vertices, indices[i], uvt[i],
TriangleCulling.NEGATIVE);
			}
			//finish
			graphics.endFill();

What do I need to do so that the bitmapdata is actually loaded?




--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Loading-JPG-bitmapdata-Something-like-Embed-but-at-runtime-tp13402.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Loading JPG bitmapdata. Something like Embed but at runtime

Posted by Alex Harui <ah...@adobe.com>.

On 8/26/16, 1:43 PM, "CodeGirl" <Mi...@yahoo.com> wrote:
>Can I just call a loader and then on complete get the bitmapdata from the
>event or do I need to have a Class referencing the bitmapData and call the
>Class to pass.   Similar to what the Embed is doing?
>
>This is the class I currently have.  Is this needed?

I couldn't tell from there what requirements you have that might need such
code.

SWFLoader is a very powerful component.  It can "load" embedded images as
well as external images.
Loader loads external images.
URLLoader loads data.

I'm still not clear on what you are loading and how.  And that can affect
when the bitmap data is available.

-Alex


Re: AW: Loading JPG bitmapdata. Something like Embed but at runtime

Posted by CodeGirl <Mi...@yahoo.com>.
Thank you Chris.  I actually ditched using the class thing.  As soon as I
realized I was going to have to create a class for every location I wanted
to load images from, that was when I decided against it.  And it wasnt
needed anyways.  Of course it didnt help when I was testing different
loaders that I had a bug as well.  I had associated the failure to the
loader.  So all that work was lost over a bug.



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Loading-JPG-bitmapdata-Something-like-Embed-but-at-runtime-tp13402p13440.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

AW: Loading JPG bitmapdata. Something like Embed but at runtime

Posted by Christofer Dutz <ch...@c-ware.de>.
Just as a side note.


I have an application in which I have image data sent back from the server and which is dislayed. The "source" of an Image doesn't have to be a Class, it can also be a ByteArray. I am currently using this to display dynamically loaded image data. The cool thing is that Flex doesn't really seem to worry about the format. I send back PNG and JPEG data as ByteArray and it just does everything correctly [?]



Chris

________________________________
Von: CodeGirl <Mi...@yahoo.com>
Gesendet: Freitag, 26. August 2016 22:43:14
An: users@flex.apache.org
Betreff: Re: Loading JPG bitmapdata. Something like Embed but at runtime

Turned out to be a bug.

Got egg in my face

I had created a function called setOffset which when I created it, it was
intended for after creation settings and so in that function, I call update.

Later, as I changed how I created my 3D image, I ended up using that
function in the create process.  So after my first object, which does not
have a texture, when it ran setOffset, it also ran update but before my
loads were complete.  And so it was the update that was causing the null
reference because the complete had not ran and that update and draw had not
been run either.

I wonder how many of the loaders would have worked it I had of had that bug
fixed?

Can I just call a loader and then on complete get the bitmapdata from the
event or do I need to have a Class referencing the bitmapData and call the
Class to pass.   Similar to what the Embed is doing?

This is the class I currently have.  Is this needed?

package views
{
        import flash.display.Bitmap;
        import mx.core.FlexGlobals;

        public class LoadedImageClass extends Bitmap
        {
                public function LoadedImageClass()
                {
                        super(CustomBarnView(FlexGlobals.topLevelApplication.customBarnView).bmd)
                }
        }
}



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Loading-JPG-bitmapdata-Something-like-Embed-but-at-runtime-tp13402p13413.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Loading JPG bitmapdata. Something like Embed but at runtime

Posted by CodeGirl <Mi...@yahoo.com>.
Turned out to be a bug.

Got egg in my face

I had created a function called setOffset which when I created it, it was
intended for after creation settings and so in that function, I call update.

Later, as I changed how I created my 3D image, I ended up using that
function in the create process.  So after my first object, which does not
have a texture, when it ran setOffset, it also ran update but before my
loads were complete.  And so it was the update that was causing the null
reference because the complete had not ran and that update and draw had not
been run either.  

I wonder how many of the loaders would have worked it I had of had that bug
fixed?  

Can I just call a loader and then on complete get the bitmapdata from the
event or do I need to have a Class referencing the bitmapData and call the
Class to pass.   Similar to what the Embed is doing?

This is the class I currently have.  Is this needed?

package views
{
	import flash.display.Bitmap;
	import mx.core.FlexGlobals;

	public class LoadedImageClass extends Bitmap
	{
		public function LoadedImageClass()
		{
			super(CustomBarnView(FlexGlobals.topLevelApplication.customBarnView).bmd)
		}
	}
}



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Loading-JPG-bitmapdata-Something-like-Embed-but-at-runtime-tp13402p13413.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Loading JPG bitmapdata. Something like Embed but at runtime

Posted by CodeGirl <Mi...@yahoo.com>.
Here is an example of the embed that works but only if I put my hard code my
images rather than loading them from a list.

		[Embed("../panels/OceanBluePanel.jpg")]
		private static const OCEANBLUEPANEL:Class;

		this.panelTexture = [new OCEANBLUEPANEL().bitmapData];


Here is where Texture is being used
			graphics.clear();
			//draw
			for (i = 0; i < len; i++) {
				graphics.beginFill(colors[i]);
				graphics.drawTriangles(vertices, indices[i], null,
TriangleCulling.NEGATIVE);
				graphics.endFill();
				graphics.beginBitmapFill(texture[i], null, true, true);
				graphics.drawTriangles(vertices, indices[i], uvt[i],
TriangleCulling.NEGATIVE);
			}
			//finish
			graphics.endFill();
			//set distance for depth sorting
			distance = position.z;



Now, here is the loader code I currently have which I get the null reference
error.
This Loader was the most elaborate of the loaders I tried

			private function ldr_CompleteHandler(e:Event):void
			{
				bmd = Bitmap(e.target.content).bitmapData;
				this.panelTexture = [new LoadedImageClass().bitmapData];
			}

			private function urlldr_CompleteHandler(e:Event):void
			{
				var bytes:ByteArray = URLLoader(e.target).data;
				var loader:Loader = new Loader();
				loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
ldr_CompleteHandler);
				loader.loadBytes(bytes);
			}
			
			private function ldr_ErrorHandler(e:Event):void
			{
				Alert.show("There has been an error Loading Image");
			}
			

//				var url:String = "panels/BrownPanel.jpg";
/*				var urlLoader:URLLoader = new URLLoader();
				var urlRequest:URLRequest = new URLRequest(url);
				urlLoader.addEventListener(Event.COMPLETE, urlldr_CompleteHandler);
				urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
				urlLoader.load(urlRequest);
*/				





--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Loading-JPG-bitmapdata-Something-like-Embed-but-at-runtime-tp13402p13412.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Loading JPG bitmapdata. Something like Embed but at runtime

Posted by CodeGirl <Mi...@yahoo.com>.
Figured you would assume I did what the examples showed.   Thats why I just
said I tried various loaders and how they say to get the data on the
complete events.  But I guess I have to say that too.

If you google about loading an image, you get all kinds of examples about
using Loaders.  URLLoaders, and then on the complete, you see all kinds of
examples on how to get the supposedly loaded data.  Which I tried em all.  

Yes, When I set up the loaders, I also added a complete event.  And it isnt
until the complete event that I tell my 3D app to read the data.  But even
then, it still gives me a null reference error.  Its as if it really doesnt
load the data until its about to display it.   Which is contrary to what you
would think a load event would do.  If I use the Embed in the code rather
than the loader, I dont get an error.  Like I said, the Embed seems to load
the information about the image at compile time hence when I run my app, the
data is there.  But for some reason when I use the loader, I get a null
reference error.  The only code change is from the embed to the loader.   I
even set up an eventlistener if there was an error but it does fire.  So it
does complete but there isnt any data.  Which is why I think it does not
load bitmapData until its about to display the image.  Not after it loads
the image.   Hence why I am asking if there is something I am doing wrong.  



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Loading-JPG-bitmapdata-Something-like-Embed-but-at-runtime-tp13402p13411.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Loading JPG bitmapdata. Something like Embed but at runtime

Posted by Alex Harui <ah...@adobe.com>.
I'm not quite sure I understand the issue.  I will note that "loading" is
typically asynchronous and the bitmap data may not be available until the
frame after the COMPLETE event.

If that isn't the issue, please try re-summarizing the problem again.

-Alex

On 8/26/16, 7:27 AM, "CodeGirl" <Mi...@yahoo.com> wrote:

>Let me revise my statement.
>
>I created a Panel Class which contained all my images as Embed and then
>created a static getImage function
>
>But even with the Embed statement in a separate class gets the same
>error. 
>Evidently, the Embed only works if its in the same glass as the setTexture
>function.   
>
>Okay, what is happening and why and what do you suggest as a solution?
>
>
>
>--
>View this message in context:
>http://apache-flex-users.2333346.n4.nabble.com/Loading-JPG-bitmapdata-Some
>thing-like-Embed-but-at-runtime-tp13402p13405.html
>Sent from the Apache Flex Users mailing list archive at Nabble.com.


Re: Loading JPG bitmapdata. Something like Embed but at runtime

Posted by CodeGirl <Mi...@yahoo.com>.
Let me revise my statement.  

I created a Panel Class which contained all my images as Embed and then
created a static getImage function

But even with the Embed statement in a separate class gets the same error. 
Evidently, the Embed only works if its in the same glass as the setTexture
function.   

Okay, what is happening and why and what do you suggest as a solution?



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Loading-JPG-bitmapdata-Something-like-Embed-but-at-runtime-tp13402p13405.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.