Solved

Picturebox array & flash movie

Posted on 2003-12-11
9
775 Views
Last Modified: 2007-12-19
i am a beginner in vb and currently working on the game "battleship." I have made 100 picturebox arrays called ComShip(x). How would i make it so that by clicking on a SPECIFIC picturebox (eg. comship(2)), THAT picturebox would display an image. Currently, when i click on ANY of the pictureboxes, the image still shows up on the specified picturebox, but that's not what i want. Is there something i can fix, such as

          Private Sub comship(2)_Click(Index As Integer)        
       instead of the normal          Private Sub comship_Click(Index As Integer)


I also have tried to put a flash movie(.swf) instead of an image, but to no avail. Do I have to add the shockwave flash movie box separately, or can i create one when a picturebox is clicked?

Please help me since i am new to this.
Thank you.
0
Comment
Question by:thundergust
  • 5
  • 3
9 Comments
 
LVL 9

Expert Comment

by:Dang123
Comment Utility
thundergust,
    If you have ComShip as an array of 100 picture boxes, this should load a picture into the clicked one.

Private Sub ComShip_Click(Index As Integer)
    ComShip(Index).Picture = LoadPicture("C:\boat.bmp")
End Sub

Dang123
0
 
LVL 9

Expert Comment

by:Dang123
Comment Utility

Here is a sample of working with a flash movie.

http://www.freevbcode.com/ShowCode.Asp?ID=1443

Dang123

0
 

Author Comment

by:thundergust
Comment Utility
i meant by clicking a specific picturebox, that picturebox will play a flash movie or image inside it. I do not want to click on any picturebox and the image still shows up.
0
 
LVL 9

Expert Comment

by:Dang123
Comment Utility
thundergust,
    Sorry, I guess I misunderstood you. After playing with the sample in the link I provided above, it looks like you would need to do one of two things. Put a flash movie player in each picture box, or replace the picture boxes with flash movie player controls. I was able to use the sample to create two flash movie players running at the same time, though performance was starting to become an issue.

    Because of the performance, you may want to use a picture box array. When one member is clicked, hide it and set the flash movie player to occupy the exact same place. Show your bomb exploding in the water or on a boat or what ever then hide the flash movie player and show the picture box again with a different picture in it.

    Let me know how you want to proceed, the sample in the link above should show you most of what you need to know about working with the flash movie.

    By the way, an image control takes less resources than a picturebox control; I would suggest using that if you just want to show pictures on the screen.

Dang123

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Expert Comment

by:Sector10
Comment Utility
Hi,

Take a look at this, this will get you on your way:

Visual Basic Source Codes:

Private Sub Form_Load()
    SWFlash.Movie = App.Path & "\Movie1.swf"
    SWFlash.Menu = False        'I don't want to see Flash Player Menu
End Sub

Private Sub SWFlash_FSCommand(ByVal command As String, ByVal args As String)
   
    If command = "ButtonClick" Then
        Select Case args
           
            Case "cmdBack": SWFlash.Back        'For Moving to Next Scene
            Case "cmdNext": SWFlash.Forward     'For Moving to Back Scene
           
            'Buttons on 2nd Scene
            Case "Page2.Command1": MsgBox "Command Button 1 Clicked.", vbInformation
            Case "Page2.Command2": MsgBox "Command Button 2 Clicked.", vbInformation
           
            'Buttons of Page3
            'Stop and Play a Movie Clip.
            'For Entrire Movie Play and Stop, Use Play and PlayStop Methods
            Case "Page3.cmdStop": SWFlash.TStopPlay "FishMovie"
            Case "Page3.cmdPlay": SWFlash.TPlay "FishMovie"
           
            'Buttons of Page4
            'SEtting and Getting Variable Values
            Case "Page4.ShowValue"
                Dim mVar As String
                On Local Error Resume Next      'There may be null value
                mVar = SWFlash.GetVariable("txtToGet")
                MsgBox "Text box Value is """ & mVar & """"
            Case "Page4.SetValue"
                mVar = InputBox("Enter Some Value.")
                If mVar <> "" Then _
                    SWFlash.SetVariable "txtToSet", mVar
           
            'Buttons of Page5
            'SEtting and Getting Object Properties
            ' 0 For X Pos
            ' 1 For Y Pos
            ' 2 and 8 For Rotate Horizantaly
            ' 3 and 9 For Rotate Vartically
            ' 6 For Alpha
            ' 10 For Rotations Clockwise/AntiClockwise
            ' 11 For Getting Object Name
            ' 15 Gives Movie Files Path (.swf)
            ' 19 For Quality
           
            Dim lVal As String
            'Move Up
            Case "Page5.cmdUp"
                lVal = SWFlash.TGetProperty("MyBall", 1)
                SWFlash.TSetProperty "MyBall", 1, CStr(CLng(lVal) - 5)
            'Move Down
            Case "Page5.cmdDown"
                lVal = SWFlash.TGetProperty("MyBall", 1)
                SWFlash.TSetProperty "MyBall", 1, CStr(CLng(lVal) + 5)
            'Move Left
            Case "Page5.cmdLeft"
                lVal = SWFlash.TGetProperty("MyBall", 0)
                SWFlash.TSetProperty "MyBall", 0, CStr(CLng(lVal) - 5)
            'Move Right
            Case "Page5.cmdRight"
                lVal = SWFlash.TGetProperty("MyBall", 0)
                SWFlash.TSetProperty "MyBall", 0, CStr(CLng(lVal) + 5)
           
           
            'Rotate Clockwise
            Case "Page5.cmdRotateDown"
                lVal = SWFlash.TGetProperty("MyBall", 10)
                SWFlash.TSetProperty "MyBall", 10, CStr(CLng(lVal) + 5)
               
            'Rotate AntiClockwise
            Case "Page5.cmdRotateUp"
                lVal = SWFlash.TGetProperty("MyBall", 10)
                SWFlash.TSetProperty "MyBall", 10, CStr(CLng(lVal) - 5)
               
            'Shrink Object Inside
            Case "Page5.cmdShrinkH"
                lVal = SWFlash.TGetProperty("MyBall", 8)
                SWFlash.TSetProperty "MyBall", 8, CStr(CLng(lVal) - 5)
            'Shrink Object OutSide
            Case "Page5.cmdDeShrinkH"
                lVal = SWFlash.TGetProperty("MyBall", 8)
                SWFlash.TSetProperty "MyBall", 8, CStr(CLng(lVal) + 5)
               
            'Shrink Object Inside Vertically
            Case "Page5.cmdDeShrinkV"
                lVal = SWFlash.TGetProperty("MyBall", 9)
                SWFlash.TSetProperty "MyBall", 9, CStr(CLng(lVal) + 5)
               
            'Shrink Object Inside Vertically
            Case "Page5.cmdShrinkV"
                lVal = SWFlash.TGetProperty("MyBall", 9)
                SWFlash.TSetProperty "MyBall", 9, CStr(CLng(lVal) - 5)
               
           
            'Set the Alpha Value of the Object
            Case "Page5.cmdAlphaUp"
                lVal = SWFlash.TGetProperty("MyBall", 6)
                If CInt(lVal) < 100 Then    'Max Value for Alpha is 100
                    SWFlash.TSetProperty "MyBall", 6, CStr(CLng(lVal) + 5)
                    'Set New Alpha to the TextBox (In Flash Movie named txtAlpha)
                    SWFlash.SetVariable "txtAlpha", CStr(CLng(lVal) + 5)
                End If
            Case "Page5.cmdAlphaDown"
                lVal = SWFlash.TGetProperty("MyBall", 6)
                If CInt(lVal) > 0 Then    'Min Value for Alpha is 0
                    SWFlash.TSetProperty "MyBall", 6, CStr(CLng(lVal) - 5)
                    'Set New Alpha to the TextBox (In Flash Movie named txtAlpha)
                    SWFlash.SetVariable "txtAlpha", CStr(CLng(lVal) - 5)
                End If

        End Select
    End If
End Sub


Flash ActionScript:

on (release) {
      fscommand("ButtonClick", "cmdBack");
}

on (release) {
      fscommand("ButtonClick", "cmdNext");
}

on (release) {
      fscommand("ButtonClick", "Page3.cmdStop");
}

on (release) {
      fscommand("ButtonClick", "Page3.cmdStop");
}

on (release) {
      fscommand("ButtonClick", "Page4.ShowValue");
}


Regards,


Paul
0
 

Author Comment

by:thundergust
Comment Utility
i think the codes for flash are a little too advanced for me, currently taking computer science 11 in a secondary school. i am still experimenting how to hide the picturebox and put a flash movie in it. the playing of the flash movie has to be simple because i have about 200 pictureboxes(computer ships and player ships). Clicking on the picturebox still doesn't work for me, so i guess the only way is to give every picturebox a specific name.
0
 
LVL 9

Expert Comment

by:Dang123
Comment Utility
thundergust,
    Something like this should get you going.

Private Sub ComShip_Click(Index As Integer)
   ComShip(Index).Visible = False
   ShockwaveFlash1.Width = ComShip(Index).Width
   ShockwaveFlash1.Height = ComShip(Index).Height
   ShockwaveFlash1.Top = ComShip(Index).Top
   ShockwaveFlash1.Left = ComShip(Index).Left
   
   'logic here to show flash movie
   
   ComShip(Index).Picture = LoadPicture("C:\boat.bmp")
End Sub

Dang123

0
 
LVL 9

Accepted Solution

by:
Dang123 earned 500 total points
Comment Utility

Sory, minor change : )

Private Sub ComShip_Click(Index As Integer)
   ShockwaveFlash1.Width = ComShip(Index).Width
   ShockwaveFlash1.Height = ComShip(Index).Height
   ShockwaveFlash1.Top = ComShip(Index).Top
   ShockwaveFlash1.Left = ComShip(Index).Left
   ComShip(Index).Visible = False
   ShockwaveFlash1.Visible = True
   
   'logic here to show flash movie
   
   ComShip(Index).Picture = LoadPicture("C:\boat.bmp")
   ShockwaveFlash1.Visible = False
   ComShip(Index).Visible = True
End Sub


0
 

Author Comment

by:thundergust
Comment Utility
oh...i just figured it out. i didn't notice the "index" in ComShip(Index). i just keep putting in a integer i created. the flash movie was also a great help. Thanks Dang123!! :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now