[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3229
  • Last Modified:

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

0
Susurrus
Asked:
Susurrus
  • 3
1 Solution
 
abelCommented:
Is your code complete? You switch from animFlashObject to currentFlashObject and the code doesn't show the initialization of the latter.

Try the code below. I haven't tested it, but blended your code with the code from this thread: http://www.programmingforums.org/post164816.html

-- Abel --

AxShockwaveFlash animFlashObject = new AxShockwaveFlash();
animFlashObject.Location = new System.Drawing.Point(0, 0);
 
this.Controls.Add(axShockwaveFlash);
//this.Show(); // Avoids InvalidActiveXStateException.
 
animFlashObject.Movie = Application.StartupPath + @"/flash/gui.swf";
animFlashObject.AllowFullScreen = "true";
animFlashObject.EmbedMovie = true;
animFlashObject.Play();
//* it is important to set Size after specifying Movie property
//* if Size is specified before, it is ignored
animFlashObject.Size = new System.Drawing.Size(1200, 700);
animFlashObject.Play();

Open in new window

0
 
abelCommented:
note, you may need to use this.Show in-between... it may handle your error (commented out above)
0
 
danaceCommented:
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

0
 
abelCommented:
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)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now