Hello,,,

Im trying open flash file on button click event, but its didn't open, when i write

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       AxShockwaveFlash1.Movie = "D:\My Project\Practice Projects\SWF-File_As_SplashScreen\SWF-File_As_SplashScreen\Resources\back_blue.swf"
       AxShockwaveFlash1.Play()
   End Sub

then its properly work and play,,
but i build this app and published so that it will not work, ri8?
im trying like this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       AxShockwaveFlash1.Movie = "|DataDirectory|\Resources\back_blue.swf"
       AxShockwaveFlash1.Play()
   End Sub

but here no response, any idea to solve this problem???
or else give me code for start swf file on load event and perfect path,,,
Please Help,,,

@Nilesh
Thanks In Adv,,,

|DataDirectory| is used to point to a database folder. Is this what you intend? If so, you need to set it in your code ahead of time. If not, is the file added as a Resource or just stored in the Resources folder?

yeah, i have stored in resource folder,
so how can i use it in code???

There might be a better way but here's one way that works. This assumes that the "Resources" folder is in your project folder.

        Dim ResourceFolder As String = ""
        Dim ResourcePath As DirectoryInfo = Directory.GetParent(Application.StartupPath)
        While ResourcePath.GetDirectories("Resources").Length = 0
            ResourcePath = ResourcePath.Parent
            If ResourcePath.FullName = ResourcePath.Root.FullName Then
                Exit While
            End If
        End While
        If ResourcePath.FullName <> ResourcePath.Root.FullName Then
            ResourceFolder = ResourcePath.FullName + "\Resources"
        End If

Basically this starts at the application folder and works its way backwards through the path to find the folder that contains the Resources folder. Then assigns the path as a string plus "Resources" to ResourceFolder

Have you added the file as an embedded resource?
i.e. can you type in your code: My.Resources.back_blue ?

If so, you will need to extract it to disk first.

give error,,,
'back_blue' is not a member of 'Resources'.
i have drag n drop that file to project resource folder..
whts wrong here??

If you want to add it as an embedded resource, use the Resources tab in the project properties.

i have already added,,

TnTinMN sir, tinstaafl sir...

When im Write this Code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        AxShockwaveFlash1.Movie = My.Resources.back_blue
        AxShockwaveFlash1.Play()
    End Sub

then it's give error like this:Error 1 Value of type '1-dimensional array of Byte' cannot be converted to 'String'.

Now am write for conversion Val(), like this:
AxShockwaveFlash1.Movie = My.Resources.back_blue

then no error occur, but gives run time error:
Argument 'Expression' cannot be converted to type 'Byte()'.

Please Help Me,,,
@Nilesh

Ok. You now got it as an embedded resource, so for the player to play the movie, you will first have to write it to the disk. I like using temporary files for this.

Public Class Form1

    Dim tempfile As String = System.IO.Path.GetTempFileName

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim strmTemp As IO.Stream = IO.File.Create(tempfile, 1024, IO.FileOptions.None)
       strmTemp.Write(My.Resources.back_blue, 0, My.Resources.back_blue.Length)
       strmTemp.Close()
       AxShockwaveFlash1.Movie = tempfile
    End Sub

    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
       ' delete the temp file
       System.IO.File.Delete(tempfile)
    End Sub

End Class

TnTinMN,
Thanks alot sir,
its working properly,,,

Now one question, can i use any of file like this???

Thanks,
@Nilesh

I'm sorry, but I do not understand what you are trying to ask.

can i use any of file( like .jpeg, .gif, .mp4, .wmv, etc...)???
using above code...

Yes, of course. Embedding a file just merges a copy of it into the executable. The My.Resources provides it a Byte array. There are also tools that allow you to retreive it is as an IO.Stream.

Edit: Some programs may what to have the proper extension (.wmv, .jpg, etc.) and a temporary filename will have a ".tmp" extension. You can rename a file using System.IO.File.Move("oldpath\filename", "oldpath\newfilename") or you can use the VB helper method My.Computer.FileSystem.RenameFile.

thanks alot sir

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.