Link to home
Start Free TrialLog in
Avatar of keshavap
keshavap

asked on

Object reference not set to an instance of an object

I have added Shockwave flash ActiveX control to the toolbox, and added an instance to the windows form. When I try to assign a movie, I'm getting System.NullReference exception (Object reference not set to an instance of an object).
code is as follows:

try
{
axShockWaveFlash.Movie = "test.swf";
}
catch (System.Exception e)
{
Messagebox.Show (e.Message + "\n" + e.StackTrace);
}

Please help me.

Keshav.
Avatar of _TAD_
_TAD_

Shouldn't that be the full path?


axShockWaveFlash.Movie = @"C:\Temp\test.swf";
Have you initialized axShockWaveFlash object??

May be you need to try something like:

ShockWaveActiveXObject axShockWaveFlash = new ShockWaveActiveXObject();

Or otherwise can you please paste your code on to what you are doing?

Siddhartha
did you put shockwave control from the toolbox on your form or what???

I see no problem, it works for me just fine!
Avatar of keshavap

ASKER

As i mentioned earlier, i have added an instance of the SWF activex control to the WinForm. So the IDE takes care of creating a wrapper and initializing the component. For brevity sake, i did not give the full path, Ok heres what the actual code snippet...

//The control is created here...
InitializeComponent ()
{
this.axSWF = new AxShockWaveFlashObjects.AxShockWaveFlash();
((System.ComponentModel.ISupportInitialize)(this.axSWF)).BeginInit ();
this.SuspendLayout ();

this.axStart.Enabled = true;
.
.
.

}

private void Form1_Load (.....)
{
try
{
axSWF.Movie = Application.StartupPath + "\\" + "test.swf";
}
catch (Exception ex)
{
.
.
}
}

and i guess you did put decleration in your class something like:

private AxShockwaveFlashObjects.AxShockwaveFlash axSWF;

btw, why dont you just drag the ctrl from your toolbox on your form set the properties and you are ready to play the movie!
I have dragged the control from the toolbox to the form. So most of the code in InitializeComponents() is auto generated. Only assigning the movie file should be dynamic. So when I assign the .swf file the error occurs.
check the Application.StartupPath value
The Application.StartupPath returns me the path of the .Exe file and the SWF file is stored there.

*The swf file is a valid one.
*the path is proper.
*the ShockWaveFlash control is properly initialized.

but when i try to assign a the movie with the full and proper  path it fails!
weird,
axShockWaveFlash1.Movie = "c:\\test.swf";


works fine for me, no problem at all!
I know it might not be that good an idea but just try to do at least these steps all over again. I mean just make a small application and add the control and try to assign Movie to it. Soemtimes weird things happen. Just give it a try.

Siddhartha


It's a bit of a stretch, but have you thrown a couple of '@' symbols into the declaration?


something like:

try
{
     axSWF.Movie = @Application.StartupPath + @"\test.swf";
}



It's a long shot, but what if the '\' are considdered esc caracters by the compiler.


Also, what is the EXACT path returned by Application.StartupPath?

is it C:\temp or C:\temp\

there is a chance you have 1 too many '\'
ASKER CERTIFIED SOLUTION
Avatar of _TAD_
_TAD_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I tried to run the same application in a different machine. It works fine. Thanks anyway.