Link to home
Start Free TrialLog in
Avatar of Susurrus
Susurrus

asked on

intialising an axShockwaveFlashObject at runtime in c#

I am using an axShockwaveFlashObject to include a flash animation in my c# application.  I can create a working AxShockwaveFlash object by draging it from the tool bar at design time, but if i try to create one through code at runtime I get the error:

Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown

I have included my code below:
try{
 
           AxShockwaveFlash animFlashObject = new AxShockwaveFlash(); 
           this.Controls.Add(animFlashObject);
           currentFlashObject.Enabled = true;
           currentFlashObject.Location = new Point(0, 0);
           currentFlashObject.Size = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
           currentFlashObject.LoadMovie(0, Application.StartupPath + @"/flash/gui.swf");
 
}catch(Exception x){
 
           MessageBox.Show(x.Message);
 
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of abel
abel
Flag of Netherlands image

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
note, you may need to use this.Show in-between... it may handle your error (commented out above)
i can't have the same error that you are having. Maybe try using a different swf file just to check if there is a problem in your current swf file.

for your code to run..i just used a string variable for the filename before using it in the LoadMovie().
I dont have an explanation though, on why it cant run on putting the name of the file/path directly.
try{
           string filename = Application.StartupPath + @"/flash/gui.swf";
           AxShockwaveFlash animFlashObject = new AxShockwaveFlash(); 
           this.Controls.Add(animFlashObject);
           animFlashObject.Enabled = true;
           animFlashObject.Location = new Point(0, 0);
           animFlashObject.Size = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
           animFlashObject.LoadMovie(0, filename);
 
}catch(Exception x){
 
           MessageBox.Show(x.Message);
 
}

Open in new window

This question is answered: the user got an exception on an unitialized object, I showed the code how to initialize properly. Please accept comment http:#24200580 (abel)