How can I reload the shockwave component or how do I get the same shockwave component to play different swf files?
Currently the only solution I have found is to place the sockwave component in its own form and reload the form.
Printable View
How can I reload the shockwave component or how do I get the same shockwave component to play different swf files?
Currently the only solution I have found is to place the sockwave component in its own form and reload the form.
Are you doing your component load in the Form_Load?
No.
here is my main form code. The vb app writes an XML file that records the path of the flv file. The swf reads in the path and plays the flv. So on my File1_Click event I couldn't find a means to reload or refresh the component with each click.
I ended up placing it in its own form and reloading the form. It works rather nicely until you go to click on the File1 again. Then the shockwave form disappears. I found some code that would let me keep the swf form always on top, but I keep saying there must be away to reload "something" and play a different flv. :)
VB Code:
Option Explicit 'makes it necessary to specify variables 'and makes sure no variable used twice Private Function CreateDOM() Dim dom Set dom = New DOMDocument30 dom.async = False dom.validateOnParse = False dom.resolveExternals = False dom.preserveWhiteSpace = True Set CreateDOM = dom End Function Private Sub File1_Click() Dim dom, node, frag, cd, attr Dim sReplaceChar As String sReplaceChar = "" 'On Error GoTo ErrorHandler Set dom = CreateDOM ' Create a processing instruction targeted for xml. Set node = dom.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'") dom.appendChild node Set node = Nothing ' Create a comment for the document. Set node = dom.createComment("sample xml file created using XML DOM object.") dom.appendChild node Set node = Nothing ' Create the root element. Dim root Set root = dom.createElement("videos") ' Add the root element to the DOM instance. dom.appendChild root ' Insert a newline + tab. root.appendChild dom.createTextNode(vbNewLine + vbTab) ' Create and add more nodes to the root element just created. ' Create a text element. Set node = dom.createElement("video") 'find and replace \ with / for flash sReplaceChar = (File1.Path & "\" & File1.FileName) sReplaceChar = Replace(sReplaceChar, "\", "/") 'node.Text = "some character data" 'node.Text = File1.Path & "/" & File1.FileName node.Text = sReplaceChar 'MsgBox (node.Text) ' Add text node to the root element. root.appendChild node Set node = Nothing ' Add a newline plus tab. root.appendChild dom.createTextNode(vbNewLine + vbTab) ' Save the XML document to a file. dom.save App.Path + "\flv.xml" Set root = Nothing Set dom = Nothing Shape1.Visible = False 'load shockwave form Unload frmshockwave Load frmshockwave frmshockwave.Show frmhome.txtInfo.Text = "" Exit Sub ErrorHandler: MsgBox Err.Description End Sub 'search for flv file Private Sub Drive1_Change() Dir1.Path = Drive1.Drive End Sub Private Sub Dir1_Change() File1.Path = Dir1.Path File1.Pattern = "*.flv" End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If UnloadMode = 0 Then Dim Msg ' Declare variable. 'Set the message text. Msg = "Do you really want to exit?" 'If user clicks the No button, stop QueryUnload. If MsgBox(Msg, vbQuestion + vbYesNo, Me.Caption) = vbYes Then Call closeAllForms 'Unload frmIntro Cancel = False Else Cancel = True End If End If End Sub
--edited----
code for shockwave form
VB Code:
Private Sub Form_Load() Call FormOnTop(Me.hWnd, True) ShockwaveFlash1.Movie = App.Path & "\XML_FLV_player.swf" frmshockwave.Caption = frmhome.File1.FileName End Sub Private Sub ShockwaveFlash1_FSCommand(ByVal command As String, ByVal args As String) If (command = "info") Then 'frmhome.txtInfo.Text = (args) frmhome.txtInfo.Text = frmhome.txtInfo.Text & args & vbNewLine Else MsgBox (args) End If End Sub
I guess the form load and unload is the most pratical solution fo rmy situation. ;)
I would avoid strickly using the Form_Load as the code in there would only be run once, when the form loaded.
Perhaps a better approach would be to put the required code in a Private Sub on the form. This sub could be called from the Form_Load, but also, because it is a sub, it could be called again after the form is loaded, and the parameters have changed.
I am not sure I understand, of course I have only had one sip of morning coffee :lol: Can you explain a little more?
A simple example. Lets say you have the following in the Form_LoadNow, after some more processing on the forms which occasions the values of these textboxes to change, you need to reset them to their original values (just pretend you need the routine to run again in order to do this).VB Code:
Private Sub Form_Load() Text1.Text = "Hack" Text2.Text = "Navarone" End Sub
Well, without unloading the form and reloading, you can't. However, if you create a sub routine on the form, you can simply call the sub again.The form is loaded, and the textboxes have their values. You do stuff which changes those values. Now you need to reset them. Instead of unloading and reloading the form, all you have to do is call the SetDefaultTextValues sub again.VB Code:
Option Explicit Private Sub SetDefaultTextValues() Text1.Text = "Hack" Text2.Text = "Navarone" End Sub Private Sub Form_Load() SetDefaultTextValues End Sub
Make sense?
Sorta makes sense. So if I understand, when my form loads, the default values are blank or they would be blank in my case. When I click the File1_Click, the new values would be added and I would then in this same File1_Click sub run the SetDefaultTextValues, correct?
Can I get away with just having one form?
I don't see why you couldn't have just one form.Quote:
Originally Posted by Navarone
Also, you probably don't want to call your Sub SetDefaultTextValues. You aren't dealing with text. You are dealing with swf files. :)
Let me see if I understand the flow of your program.
Your form loads, but at that time, nothing is happening.
After the form loads, an swf file is selected using your File1 control.
The name of the selected file is passed onto code that will actually play, or display, or do whatever it is you do, with swf files.
Once this is done, you would like the ability to repeat the process by selecting another swf file, and doing the playing/whatevering all over again.
Is this the scenerio?
That is correct. ;)
See I originally had just one form with the shockwave component, but I didn't know how to reload the values or component, so I went to 2 forms.
Ok. With this being the case, you don't need anything the form load unless you want to hardcode a swf file name. That would mean the same file played EVERY time you loaded your form, and that would get old very quick.
It looks like all of the code to do what you want is in the click event of File1.
I would take that code out of that and put it in a Sub. Call it something like PlaySWF. I would add a parameter to the sub for the file name. I would also take what was selected from File1_Click and display it in a textbox. That would give the user the opportunity to verify that they selected the file they wanted, and didn't select something by mistake.
I would add a command button called cmdPlay, and call the sub from the click event of the command button. A quick example:Make sense?VB Code:
Option Explicit Private Sub PlaySWF(pstrFileName As String) 'code here to play the passed file name End Sub Private Sub File1_Click() txtSWF.Text = File1.FileName End Sub Private Sub cmdPlay_Click() PlaySWF txtSWF.Text End Sub
Now, you can play whatever you want just but selecting it, and clicking the command button, and you can do it over and over and over again. Plus, you only need one form.
Ok, let me try this and I'll get back to you with how I make out.
Thanks.
It should work like a champ. I've no idea how to play an .swf file, but if you can handle that part, then I'm pretty sure I will be able to answer any other questions regarding the process and/or program flow for you. :)Quote:
Originally Posted by Navarone
ok, here is what I have. Everything is on one form.
When I click the File1_Click, it writes a XML document called flv.xml. Also, when I click the File1_Click the Shockwave component inturn loads the swf - XML_FLV_player.swf. This swf reads the XML file and knows which flv file to play.
So, when I click File1_Click the first time the correct flv plays, but if I click again, it will not play. The XML document is getting updated but the shockwave component isn't reloading.
VB Code:
Option Explicit Private Function CreateDOM() Dim dom Set dom = New DOMDocument30 dom.async = False dom.validateOnParse = False dom.resolveExternals = False dom.preserveWhiteSpace = True Set CreateDOM = dom End Function Private Sub File1_Click() Dim dom, node, frag, cd, attr Dim sReplaceChar As String sReplaceChar = "" 'On Error GoTo ErrorHandler Set dom = CreateDOM ' Create a processing instruction targeted for xml. Set node = dom.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'") dom.appendChild node Set node = Nothing ' Create a comment for the document. Set node = dom.createComment("sample xml file created using XML DOM object.") dom.appendChild node Set node = Nothing ' Create the root element. Dim root Set root = dom.createElement("videos") ' Add the root element to the DOM instance. dom.appendChild root ' Insert a newline + tab. root.appendChild dom.createTextNode(vbNewLine + vbTab) ' Create and add more nodes to the root element just created. ' Create a text element. Set node = dom.createElement("video") 'find and replace \ with / for flash sReplaceChar = (File1.Path & "\" & File1.FileName) sReplaceChar = Replace(sReplaceChar, "\", "/") 'node.Text = "some character data" 'node.Text = File1.Path & "/" & File1.FileName node.Text = sReplaceChar 'MsgBox (node.Text) ' Add text node to the root element. root.appendChild node Set node = Nothing ' Add a newline plus tab. root.appendChild dom.createTextNode(vbNewLine + vbTab) ' Save the XML document to a file. dom.save App.Path + "\flv.xml" Set root = Nothing Set dom = Nothing Shape1.Visible = False ShockwaveFlash1.Movie = App.Path & "\XML_FLV_player.swf" 'frmshockwave.Caption = frmhome.File1.FileName 'load shockwave form 'Unload frmshockwave 'Load frmshockwave 'frmshockwave.Show frmhome.txtInfo.Text = "" Exit Sub ErrorHandler: MsgBox Err.Description End Sub 'search for flv file Private Sub Drive1_Change() Dir1.Path = Drive1.Drive End Sub Private Sub Dir1_Change() File1.Path = Dir1.Path File1.Pattern = "*.flv" End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If UnloadMode = 0 Then Dim Msg ' Declare variable. 'Set the message text. Msg = "Do you really want to exit?" 'If user clicks the No button, stop QueryUnload. If MsgBox(Msg, vbQuestion + vbYesNo, Me.Caption) = vbYes Then Call closeAllForms 'Unload frmIntro Cancel = False Else Cancel = True End If End If End Sub Private Sub ShockwaveFlash1_FSCommand(ByVal command As String, ByVal args As String) If (command = "info") Then 'frmhome.txtInfo.Text = (args) frmhome.txtInfo.Text = frmhome.txtInfo.Text & args & vbNewLine Else MsgBox (args) End If End Sub Private Sub PlaySWF(pstrFileName As String) 'code here to play the passed file name ShockwaveFlash1.Movie = App.Path & "\XML_FLV_player.swf" End Sub
Does anything happen on the second click?
Have you stepped through the code to see what is actually going on?
I have stepped thru the application and on the second click nothing happens in the shockwave control. However, i did verify that the correct path to the flv is saved to the XML file on the second click, so there is no problem with the file name being the same or not getting updated.
I added the following to the File1_click event and the shockwave control works correctly on the second click and any subsequent clicks.
VB Code:
Unload frmhome Load frmhome frmhome.Show