Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Error #1009: Cannot access a property or method of a null object reference.

Community Beginner ,
Jan 29, 2024 Jan 29, 2024

I have the following error, when i convert swf file to gfx using scaleform exporter,
Note that
I can call other functions to set the width or the position of the button or the ImageLoader and it works, Only SetImagePath fails, so I can use other function to access the ImageLoader and set it's position!

This has nothing to do with the fact that I am trying to pass a DDS file, I have this issue with JPG too, the code worked when I passed a JPG file in adobe animate but i get this error when I try to convert the swf to gfx using scaleform exporter
for now Adobe Animate won't let me load a dds file for some reason unlike AS2

[Warning] <Flash> The method LoaderInfo::sharedEventsGet() is not implemented [MyButton.gfx]
[Error] <Flash> TypeError: Error #1009: Cannot access a property or method of a null object reference.
at fl.display::ProLoader instance constructor()
at fl.containers::UILoader/initLoader()
at fl.containers::UILoader/load()
at MyButton/SetImagePath()
at MyButton_fla::MainTimeline/SetImagePath() [MyButton.gfx]
package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.net.URLRequest;
	import fl.containers.UILoader; 
	import fl.display.ProLoader; 
	public class MyButton extends MovieClip
	{
		public function ButtonWithImage()
		{
			stop();
			buttonMode = true 
			mouseChildren = false;
		}

		public function SetImagePath(newPath: String): void
		{
			ImageLoader.load(new URLRequest("img://TEXID:"+newPath));
		}
	}
}
var newButton = new MyButton();
newButton.ImageLoader.addEventListener(Event.COMPLETE, OnCompleteHandler);
SetImagePath("test.dds");

function OnCompleteHandler(loadEvent:Event)
{
	addChild(loadEvent.currentTarget.content);
}

function SetImagePath(newPath: String): void
{
	newButton.SetImagePath(newPath);
}

ImageLoader is a UI component, as you can see I have the loader in 3 the Image Layer and it span over 3 frames. adobe animate doesn't complain, it compiles and works, so why the gfx fails

Mohamed349277375n1m_0-1706554399579.pngexpand image

so Any Idea how to fix "Error #1009: Cannot access a property or method of a null object reference. "
optional request how to load a dds file in AS3, in adobe animate, but this is low priority

 

882
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2024 Jan 29, 2024

I am not a coder but it doesn't look like you gave the images an instance name, which is how it would know to call on these images to load in. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 29, 2024 Jan 29, 2024

First, Thanks for help,
can you clarify, what do you mean that i need to give instance name? do you mean give instance name of the loader? as you can see in the picture, The UILoader has ImageLoader as InstanceName, and I can access ImageLoader from the gfx.
and in the code I let it know which Image to load by passing the name of the file to the loader, the newPath is the file it needs to load in the loader

ImageLoader.load(new URLRequest("img://TEXID:"+newPath));

Am I missing something more??

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2024 Jan 29, 2024

in your publish setting, tick "permit debugging".  retest.

 

the line number triggering the error will be listed in the error message.  what is the line triggering the error?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 29, 2024 Jan 29, 2024

 

 [object UILoader] [MyButton.gfx] // <-- I did a  trace on ImageLoader this is the result

[Error] <Flash> TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at fl.display::ProLoader instance constructor()
	at fl.containers::UILoader/initLoader()
	at fl.containers::UILoader/load()
	at MyButton/SetImagePath()[E:\Assets\Cry;;MyButton.as:58]
	at MyButton_fla::MainTimeline/SetImagePath()[MyButton_fla.MainTimeline::frame1:8] [MyButton.gfx]

 

I changed the code bit a little to try to figure out the cause, I added couple traces(breadcrumbs) etc
The last line on the call stack that triggered the error was

ImageLoader.load(new URLRequest("img://TEXID:"+newPath));

as i showed I can see that the Image loader Object UILoader,

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2024 Jan 29, 2024

what's line 58 of MyButton.as?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 29, 2024 Jan 29, 2024

 line 58 of MyButton.as is

ImageLoader.load(new URLRequest("img://TEXID:"+newPath));

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2024 Jan 29, 2024

ImageLoader isn't defined at that location.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 29, 2024 Jan 29, 2024

Nah It's not that, i did a nice trick

public function LoadImage(): void
{	
	trace("LoadImage pre");
	trace(ImagePath); 
	trace(ImageLoader + "1"); // The Main one that everyone says it's not defined
	trace(ImageLoader2 + " 2"); // Custom made UILoader, defined in ctor
	trace(ImageLoader3 +  " 3");// undefined UILoader, I didn't define to see what it will look like
		
	ImageLoader2.load(new URLRequest("img://TEXID:"+ImagePath));
	trace("LoadImage post");
}

The result of this test

<23:44:03> <Flash>  [MyButton.gfx]
<23:44:03> <Flash> LoadImage pre [MyButton.gfx]
<23:44:03> <Flash>  [MyButton.gfx]
<23:44:03> <Flash> background1.dds [MyButton.gfx]
<23:44:03> <Flash>  [MyButton.gfx]
<23:44:03> <Flash> [object UILoader]1 [MyButton.gfx]
<23:44:03> <Flash>  [MyButton.gfx]
<23:44:03> <Flash> [object UILoader] 2 [MyButton.gfx]
<23:44:03> <Flash>  [MyButton.gfx]
<23:44:03> <Flash> null 3 [MyButton.gfx]
<23:44:03> <Flash>  [MyButton.gfx]
<23:44:03> [Warning] <Flash> The method LoaderInfo::sharedEventsGet() is not implemented [MyButton.gfx]
<23:44:03> [Error] <Flash> TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at fl.display::ProLoader instance constructor()
	at fl.containers::UILoader/initLoader()
	at fl.containers::UILoader/load()
	at MyButton/LoadImage()[E:\Assets\Cry;;MyButton.as:72]
	at MyButton/SetImagePath()[E:\Assets\Cry;;MyButton.as:61]
	at MyButton::as/SetImagePath()[MyButton.as::frame1:8] [Libs/UI/MyButton.gfx]

Observation
since It said null in ImageLoader3 when I didn't define it, so in when I used UILoader Component, it worked fine, the error is from somewhere else
My Guess this could be related to where the MyButton.as is defined, missing header or something else, since i am new to AS I am clueless, but my code works and it can access the loader component without defining it, it must be some weird settings

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 29, 2024 Jan 29, 2024
package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.net.URLRequest;
	import fl.containers.UILoader; 
	import fl.display.ProLoader; 
	public class MyButton extends MovieClip
	{
               var ImageLoader3 : UILoader;
		var ImageLoader2 : UILoader;
		var ImagePath: String;
		public function ButtonWithImage()
		{
			stop();
			buttonMode = true 
			mouseChildren = false;
		}

		public function SetImagePath(newPath: String): void
		{
			ImagePath = newText;
				trace("ImagePath succeed");
			LoadImage();
		}
		public function LoadImage(): void
		{	
		trace("LoadImage pre");
		trace(ImagePath);
		trace(ImageLoader + "1");
		trace(ImageLoader2 + " 2");
		trace(ImageLoader3 +  " 3");

		ImageLoader2.load(new URLRequest("img://TEXID:"+ImagePath));
		trace("LoadImage post");
		}

	}
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2024 Jan 29, 2024

copy the imageloader reference from your class 

 

drag the loader component off-stage in mybutton

 

drag a loader component from your library or component panel onto the mybutton stage and paste the copied instance name into the properties panel.  make sure there are no leading or trailing spaces.

 

retest.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 29, 2024 Jan 29, 2024

now it no longer works in adobe too lol, no errors in adobe animate, just a blank screen

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2024 Jan 29, 2024

you're doing something wrong.

 

save your fla in a new directory and save your classes in the same directory (except those with a package designation).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 29, 2024 Jan 29, 2024

it was because i moved addEventListener(Event.COMPLETE inside the MyButton, I moved it back to the main layer, it worked again in adobe, and the error remains the same after i export it to gfx.
I'll call it a day
Thanks for help

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2024 Jan 29, 2024

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 29, 2024 Jan 29, 2024

It may be that you have no variable called "ImageLoader" on your MyButton class. I think you have two options. Define a public class variable that matches the same type and stage instance name. Flash will automatically fill the public variable with the stage instance.

The seond option with be to open the publish settings for your project, go to the actionscript settings, and enable the "automatically declare stage instances" option. Doing this will allow you to reference stage instances in the linked class without defining the public variable yourself. I am speaking from mostly AS3 knowledge though.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 29, 2024 Jan 29, 2024

As for option #2 I already have "automatically declare stage instances" enabled, so that's not it
As for option #1 I can make a member variable, but how to define " stage instance name" from the code?
I made a member variable like

var ImageLoader2 : UILoader;


and in the constructor I Initalized it like

ImageLoader2 = new UILoader();

and renamed ImageLoader to ImageLoader2 And I still have the same error!

also, note that I showed in the picture above the UILoader exist inside the button, I can call other functions that access ImageLoader,  and I did a trace and the variable is not null. + it compiled and it works in adobe animate.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2024 Jan 29, 2024

where is ImageLoader defined?  ie, is it on MyButton?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 29, 2024 Jan 29, 2024

ImageLoader the default one is defined inside the button by dragging a Loader component and naming it ImageLoader
ImageLoader2 Is defined inside MyButton class, and initialized inside the ctor
ImageLoader3 Is defined inside MyButton class, but it's not initalized for testing

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 29, 2024 Jan 29, 2024

Correcting the code snippet

package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.net.URLRequest;
	import fl.containers.UILoader; 
	import fl.display.ProLoader; 
	public class MyButton extends MovieClip
	{
		var ImageLoader3 : UILoader;
		var ImageLoader2 : UILoader;
		var ImagePath: String;
		public function MyButton ()
		{
			stop();
			buttonMode = true 
			mouseChildren = false;
			ImageLoader2 = new UILoader();
			BindListners();
		}

		public function SetImagePath(newPath: String): void
		{
			ImagePath = newText;
				trace("ImagePath succeed");
			LoadImage();
		}
		public function LoadImage(): void
		{	
		trace("LoadImage pre");
		trace(ImagePath);
		trace(ImageLoader + "1");
		trace(ImageLoader2 + " 2");
		trace(ImageLoader3 +  " 3");

		ImageLoader2.load(new URLRequest("img://TEXID:"+ImagePath));
		trace("LoadImage post");
		}

	}
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 29, 2024 Jan 29, 2024

You want it to be public. If you dont add public then it is implictly private.

public var ImageLoader3 : UILoader;

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 29, 2024 Jan 29, 2024
I mean ImageLoader, the name that matches your stage instance.
public var ImageLoader : UILoader;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 29, 2024 Jan 29, 2024

Yeah I did that, it didn't work

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 30, 2024 Jan 30, 2024

It could be a result of scaleform incompatibility! this is the only reason I can think of, and since i dont have the scaleform source code I will assume that is the reason since it works in adobe but it does not work with scaleform

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 30, 2024 Jan 30, 2024
LATEST

I was right it was scaleform AS3 compatibility issue, it was the source of the bug, I moved to a compatible loader and the error is gone
https://help.autodesk.com/view/SCLFRM/ENU/?guid=__scaleform_help_flash_support_as3_class_html

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines