Solved

Picturebox array & flash movie

Posted on 2003-12-11
9
778 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
ID: 9922139
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
ID: 9922214

Here is a sample of working with a flash movie.

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

Dang123

0
 

Author Comment

by:thundergust
ID: 9926055
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
ID: 9928171
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:Sector10
ID: 9930564
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
ID: 9943478
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
ID: 9943558
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
ID: 9943570

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
ID: 10045757
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 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