Create animated Flash movies from PB - with running example!

Share your advanced PureBasic knowledge/code with the community.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Create animated Flash movies from PB - with running example!

Post by ricardo »

You will need to download Bukoo dll http://bukoo.sourceforge.net/ and use the msscript library

Code: Select all

;Coded by Ricardo
;Change the jpg file names by some that you have in the same folder, must be something small

Function CreateSwf(Texto)
    Dim mv, obj, txt, font
    Dim btn, act, txt1(100), font1(100)
    Dim Fname
    Fname = "sample.swf" ' The file that will be created
    Set Movie = CreateObject("swfobjs.swfMovie")
    Set obj = CreateObject("swfobjs.swfObject")
    Set obj1 = CreateObject("swfobjs.swfObject")
    Set btn = CreateObject("swfobjs.swfObject")
    Set act = CreateObject("swfobjs.swfAction")

    ' Set moive attribute
    With Movie
        .SetSize 6000 * 1.3, 4000 * 1.3
        .SetFrameBkColor 255, 255, 255
        .SetFrameRate 20
    End With
'Need to find a way that the outfile has the desire size
'Flash1.Width = 6000 * 1.3
'Flash1.Height = 4000 * 1.3

Set pic = CreateObject("swfobjs.swfObject")
pic.MakePicture 300, 300, 650, 650, 450, 450, "any.JPG"
'top, left, width,height (in twips inside the swf), the 2 last in pixels
'Los 2 primeros son top y left, los 2 siguientes son widht y height en twips dentro del swf y los 2 ultimos en pixeles el rectangulo que tomara del bmp o jpg
Movie.AddObject pic ' Add picture

'Making the blocks
With obj
        .MakePolygon 500, 500
        .AddStraightLine 0, 3000
        .AddStraightLine 3000, 0
        .AddStraightLine 0, -3000
        .AddStraightLine -3000, 0
        .SetSolidFill 128, 0, 128, 70
End With
obj.SetDepth 1
Movie.AddObject obj

With obj1
        .MakePolygon 3000, 500
        .AddStraightLine 0, 2500
        .AddStraightLine 2500, 0
        .AddStraightLine 0, -2500
        .AddStraightLine -2500, 0
        .SetSolidFill 18, 250, 18, 20
End With

Movie.AddObject obj1

For i = 0 To 320
Movie.GotoFrame i
Movie.RemoveObject pic
Movie.RemoveObject obj
'Here we make the image falling down, a very nice effect it fall very far away!!!
pic.Translate i * 20, i * 20
pic.scaleEx (65536 * 10) / (i + 1), (65536 * 10) / (i + 1)
pic.Rotate 65536 * (i * 10)
obj.Rotate -65536 * (i * 1)
Movie.AddObject pic
Movie.AddObject obj
Next

For i = 0 To 320
Movie.GotoFrame i
Movie.RemoveObject obj1
obj1.Rotate 65536 * (i * 1)
Movie.AddObject obj1
Next
    Set font = CreateObject("swfobjs.swfObject")
    With font
        .MakeFont "Arial"
        .AddGlyph "Arial", "Flash", Asc("Hp")
        .AddGlyph "Arial", " Example", Asc("i")
        .AddGlyph "Arial", "http://www.purebasic.com", Asc("A")
    End With
    
    Set txt = CreateObject("swfobjs.swfObject")
    With txt
        .MakeTextEx "Hpi", font, 1270, 870, 1000
        .SetSolidFill 128, 128, 128, 100
    End With
    Movie.GotoFrame 0
    Movie.AddObject txt
    
    With txt
        .MakeTextEx "Hpi", font, 1200, 800, 1000
        .SetSolidFill 0, 0, 255, 255
    End With
    Movie.GotoFrame 0
    Movie.AddObject txt
    
For i = 0 To 100
    'On Error Resume Next
Movie.GotoFrame i
Movie.RemoveObject txt
If i * 5 < 255 Then
    txt.SetSolidFill 0, 0, 255, 255 - (i * 5)
    End If
Movie.AddObject txt
Next


'////////////////////////////////////
'---VAMOS A INTENTAR ANIMAR TEXTO
'We will try to animate some text!!!!!!!!!


Dim Cuantas
Dim Contador
Dim Letra
Dim Donde
Dim Transparencia
Dim LastLetra
Dim Espacio
Dim LetterSize
Dim FactorEscala
LetterSize = 300
Dim MYTEXT
MYTEXT = Texto
Cuantas = Len(MYTEXT)

For i = 1 To Cuantas
Set font1(i) = CreateObject("swfobjs.swfObject")
    With font1(i)
        .MakeFont "Arial"
    End With
Set txt1(i) = CreateObject("swfobjs.swfObject")
Letra = Mid(MYTEXT, i, 1) 'Pick one letter at time
font1(i).AddGlyph "Arial", Letra, Asc(Letra) 'Add letter to the object
With txt1(i)
        'Trying to mantain similar distance betwen different letters.. not all use the same space
        If LastLetra = "l" Or LastLetra = "i" Or LastLetra = "j" Then
            Espacio = Espacio + (LetterSize * 0.21)
        ElseIf LastLetra = "f" Or LastLetra = "r" Then
            'estas letras tienen menos espaciado
            Espacio = Espacio + (LetterSize * 0.3)
        ElseIf LastLetra = "t" Then
            Espacio = Espacio + (LetterSize * 0.25)
        ElseIf LastLetra = "s" Then
            Espacio = Espacio + (LetterSize * 0.45)
        ElseIf LastLetra = "o" Or LastLetra = "p" Or LastLetra = "q" Or LastLetra = "n" Then
            Espacio = Espacio + (LetterSize * 0.5)
        ElseIf LastLetra = "w" Then
            Espacio = Espacio + (LetterSize * 0.65)
        ElseIf LastLetra = "m" Then
            Espacio = Espacio + (LetterSize * 0.75)
        Else
            'espaciado Normal
            'Normal space
            Espacio = Espacio + (LetterSize * 0.49)
        End If
        LastLetra = Letra
        .MakeTextEx Letra, font1(i), Espacio, 2500, LetterSize
        .SetSolidFill 255, 128, 128, 1
End With
Movie.GotoFrame Donde
Movie.AddObject txt1(i)
Transparencia = 1
FactorEscala = 155 '75 '155'310
'ADD THE TEXT TO THE FRAME WITH FX
'Wowwwwwwww here we go !!!!!!!!
For ii = Donde + 1 To Donde + 30
Transparencia = Transparencia + 7
Movie.GotoFrame ii
Movie.RemoveObject txt1(i)
txt1(i).scaleEx (65535 * 10) / FactorEscala + 1, (65535 * 10) / FactorEscala + 1
FactorEscala = FactorEscala - 10
txt1(i).SetSolidFill Transparencia, 0, Transparencia, Transparencia
txt1(i).Rotate -65536 * (ii * 50)
Movie.AddObject txt1(i)
Next
Movie.RemoveObject txt1(i)
txt1(i).scaleEx (LetterSize * 35.565) * 2, (LetterSize * 35.565) * 2
txt1(i).Rotate 0
Movie.AddObject txt1(i)
Donde = ii - 20
Next


'---FIN ANIMACION DE TEXTO
' END OF TEXT ANIMATION... WE DONE IT !!!! HURRA !!!
    
'//////////////////////////////////////////////////////////////// CREA LA PELICULA
'CREATE THE SWF
 Movie.WriteMovie Fname

    Set Movie = Nothing
    Set obj = Nothing
    Set txt = Nothing
    Set font = Nothing
    Set btn = Nothing
    Set act = Nothing
    CreateSwf = 1
msgbox "Done!"
End Function
CreateSwf("Flash from PureBasic")
Have fun!!
Last edited by ricardo on Tue Sep 21, 2004 5:31 am, edited 1 time in total.
ARGENTINA WORLD CHAMPION
User avatar
J. Baker
Addict
Addict
Posts: 2188
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

Where do you get this library, can't seem to find it.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post by GreenGiant »

How's this line going to work (just one example there are several things that seem wrong)?

Code: Select all

Function CreateSwf(Texto)
Surely a library can't add new keywords. Only functions with brackets. Unless I'm wrong about that, a lot of your code doesnt really look like PB code.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

GreenGiant wrote:How's this line going to work (just one example there are several things that seem wrong)?

Code: Select all

Function CreateSwf(Texto)
Surely a library can't add new keywords. Only functions with brackets. Unless I'm wrong about that, a lot of your code doesnt really look like PB code.
Yes its not PB code its vbs code, you can run it from PB using the msscript lib.
ARGENTINA WORLD CHAMPION
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post by GreenGiant »

D'oh, now it makes sense, sorry. I couldn't find the lib so I didn't know what it did. Guess the name should have been a clue :P
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

GreenGiant wrote:D'oh, now it makes sense, sorry. I couldn't find the lib so I didn't know what it did. Guess the name should have been a clue :P
Which lib you cant find?
ARGENTINA WORLD CHAMPION
User avatar
J. Baker
Addict
Addict
Posts: 2188
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

I get an error that
Line4: 'CreateSwf' is not a valid opertor
I have the dll and the msscriptcontrol lib as well. Also, ran regsvr32 swfobjs.dll
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
Tommeh
Enthusiast
Enthusiast
Posts: 149
Joined: Sun Aug 29, 2004 2:25 pm
Location: United Kingdom

Post by Tommeh »

Shouldnt it be very possible to convert this to PB then? :o
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3943
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Post by wilbert »

This is what interface maker reported but I don't know how to create such an object. :?:

Code: Select all

Interface IswfMovie Extends IDispatch
  WriteMovie(a)
  SetSize(a,b)
  SetFrameRate(a)
  get_filename(a)
  put_filename(a)
  AddObject(a)
  GotoFrame(a)
  SetFrameBkColor(a,b,c)
  RemoveObject(a)
  AddAction(a)
  MakeMovie()
  SetTempDir(a)
  get_Content(a)
  DeleteTempFile()
  ReadFileContent(a,b)
EndInterface

Interface IswfObject Extends IDispatch
  get_ObjectType(a)
  put_ObjectType(a)
  MakeRectangle(a,b,c,d)
  MakeCircle(a,b,c)
  MakePolygon(a,b)
  MakeOval(a,b,c,d)
  SetLineWidth(a)
  SetLineColorA(a,b,c,d)
  SetSolidFill(a,b,c,d)
  SetLinearFill(a,b,c,d,e,f,g,h)
  SetLinearFillCenter(a,b)
  SetRadialFill(a,b,c,d,e,f,g,h)
  SetRadialFillCenter(a,b)
  Translate(a,b)
  Rotate(a)
  Scale(a,b)
  SetNoFill()
  AddCurvedLine(a,b,c,d)
  AddStraightLine(a,b)
  Delete()
  MakeEditText(a,b,c,d,e)
  SetEditTextHeight(a)
  SetEditTextEditable(a)
  SetEditTextColor(a,b,c)
  MakePicture(a,b,c,d,e,f,g)
  SetDepth(a)
  MakeSound(a)
  MakeButton(a,b,c,d)
  QueueEvent(a,b)
  SetBitmapFillJpeg(a,b,c)
  MakeFont(a)
  MakeText(a,b)
  AddGlyph(a,b,c)
  MakeButtonSimple(a,b,c,d,e,f,g,h,i)
  SetLineColor(a,b,c,d)
  AddGlyphEx(a,b,c,d)
  MakeTextEx(a,b,c,d,e)
  ScaleEx(a,b)
  MakeTextSimple(a,b,c,d,e)
  AddNewPath(a,b)
EndInterface

Interface IswfAction Extends IDispatch
  MakeActionStop()
  MakeActionPlay()
  MakeActionGotoFrame(a)
  MakeActionGotoURL(a)
  MakeActionGotoURLTarget(a,b)
EndInterface
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

J. Baker wrote:I get an error that
Line4: 'CreateSwf' is not a valid opertor
I have the dll and the msscriptcontrol lib as well. Also, ran regsvr32 swfobjs.dll
No, but the failure is that you are trying to compile it as PB code and its not.

This code should be inyected into the msscript control as vbs code and then you will see it run.

I will make an example to show what i mean.
ARGENTINA WORLD CHAMPION
User avatar
J. Baker
Addict
Addict
Posts: 2188
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

Ok thanks, as I haven't used the msscript yet and have little idea what to do with it.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Ready.

Download the zip file (everything inside to create an awesome Flash movie with animated text and images!!) and test it.

Look at the ReadMe file first.

Play a while with the vbs code (its very easy to understand!), and share your ideas, additions, etc. :)

http://www.getafile.com/cgi-bin/merlot/ ... as/swf.zip

*Zip includes ALL needed files.
ARGENTINA WORLD CHAMPION
User avatar
J. Baker
Addict
Addict
Posts: 2188
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

Works great ricardo and I understand whats going on now. Back to study it some more. :D
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
User avatar
J. Baker
Addict
Addict
Posts: 2188
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

Another question, what is anyimage.gif for? Looks like you set it, then romove it.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

J. Baker wrote:Another question, what is anyimage.gif for? Looks like you set it, then romove it.
If i remember (the code is old and maybe unclean) the GIF is the little block that seams to fall down.

The way the code works is adding something to one frame, then removing it for the next frame and adding it in a different position in this new frame.
Flash movie is a set of frames, then you can add objects in any frame but for giving the idea of movement, you should remove it for thr next frame, move it a little and ad it in this new position.

Look this part of the code

Code: Select all

For i = 0 To 320
Movie.GotoFrame i
Movie.RemoveObject pic
Movie.RemoveObject obj
'Here we make the image falling down, a very nice effect it fall very far away!!!
pic.Translate i * 20, i * 20
pic.scaleEx (65536 * 10) / (i + 1), (65536 * 10) / (i + 1)
pic.Rotate 65536 * (i * 10)
obj.Rotate -65536 * (i * 1)
Movie.AddObject pic
Movie.AddObject obj
Next
We go to each frame, remove the objects (if any for the last frame), move them a little and adding it to this frame and so on for 320 frames.

The text part is almost the same.

I do some wired stuff to make the text movement, but the idea is the same.

The great thing about Flash is that let you manipulate each object, translating, rotating and scaling it, so you can simulate complex and interesting movements.
Also you can change the transparency of the objects to complete sophisticated combinations of rotation, translation, scale it and even some others like transparency.

You do all this inside a loop, going to the next frame each time.

One last point:

You can return at any moment to any frame and add another object, so you can work each object at one time, then you dont have to manipulate all the things at the same time.

I hope i explain myself.
ARGENTINA WORLD CHAMPION
Post Reply