~ubuntu-branches/ubuntu/lucid/ming/lucid

« back to all changes in this revision

Viewing changes to perl_ext/SWF/Movie.pm

  • Committer: Bazaar Package Importer
  • Author(s): Ilya Barygin
  • Date: 2010-02-11 10:57:41 UTC
  • mfrom: (2.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100211105741-lzpmxc0703c4bo1w
Tags: 1:0.4.3-1ubuntu1
* Merge from Debian unstable (LP: #192664), remaining changes:
  - Python 2.6 transition:
    - debian/rules:
      + Include /usr/share/python/python.mk.
      + Add py_setup_install_args macro to setup.py install.
      + Installed modules differ between python versions and can't be shared,
        use DH_PYCENTRAL=nomove.
    - Remove unnecessary debian/python-ming.{dirs,files}, Python 2.3 is not
      supported anymore.
* debian/control: separate dependencies by commas.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# ====================================================================
2
2
# Copyright (c) 2000-2003 by Soheil Seyfaie. All rights reserved.
 
3
#           (c) 2009 A.Kleine
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the same terms as Perl itself.
5
6
# ====================================================================
6
7
 
7
 
# $Id: Movie.pm,v 1.4 2003/01/21 00:23:01 soheil Exp $
 
8
# $Id: Movie.pm,v 1.10 2009/03/09 16:53:33 akleine Exp $
8
9
 
9
10
package SWF::Movie;
10
11
use SWF();
15
16
 
16
17
sub streamMp3{
17
18
    my ($movie,$filename) = @_;
18
 
    $movie->setSoundStream(new SWF::Sound($filename));
 
19
    $movie->setSoundStream(new SWF::SoundStream($filename));
19
20
}
20
21
 
21
22
sub output{
27
28
    return &$output_method(@_);
28
29
}
29
30
 
30
 
 
31
31
1;
 
32
 
32
33
__END__
33
34
 
34
35
=head1 NAME
35
36
 
36
 
        SWF::Movie - SWF Movie class
 
37
SWF::Movie - SWF Movie class
37
38
 
38
39
=head1 SYNOPSIS
39
40
 
40
41
        use SWF::Movie;
41
42
 
42
43
        $m = new SWF::Movie();
43
 
        $m = new SWF::MovieWithVersion(version);
 
44
        $m = SWF::Movie::newSWFMovieWithVersion(8);
44
45
 
45
46
=head1 DESCRIPTION
46
47
 
47
48
SWF::Movie is the root object of your flashfile. It contains all your other objects you want in your movie.
48
 
Ming supports many Flash4 and Flash5 features and some of Flash MX(Flash6).
 
49
Ming supports many Flash4, Flash5 F6,7,8,9.. features.
49
50
 
50
51
The SWF::Movie object contains information like the flashversion, the size, the frames per second, the background color. Except that, the SWF::Movie behaves like 
51
 
a SWF::MovieClip. It only cannot be added to another SWF::Movie or SWF::MovieClip. ;-)
 
52
a SWF::MovieClip. It only cannot be added to another SWF::Movie or SWF::MovieClip.
52
53
 
53
54
Notice: The version of your flashmovie can be set by the object SWF. See SWF for more details.
54
55
 
56
57
 
57
58
=over
58
59
 
59
 
=item add(SWFObject)
 
60
=item $m = new SWF::Movie()
 
61
 
 
62
Creates a Movie object. 
 
63
 
 
64
=item $m = newSWFMovieWithVersion(version)
 
65
 
 
66
Creates a Movie object with version value (e.g. 8) set.
 
67
 
 
68
=item $displayItem=$m->add($SWFObject)
60
69
 
61
70
Add an instance of a SWF-object to your current frame. The returnvalue is a SWF::DisplayItem.
62
71
 
63
 
        Possible SWF-objects are:
64
 
        
 
72
        Some possible SWF-objects are:
 
73
 
65
74
        SWF::Action
66
75
        SWF::MovieClip
67
76
        SWF::Shape
68
77
        SWF::Sound
69
78
        SWF::Text
70
79
        SWF::TextField
71
 
        
 
80
        SWF::Bitmap
 
81
        SWF::PrebuiltClip
 
82
 
72
83
        $m->add($shape); # possible, but not more accessible for us
73
84
        $shape_1 = m->add($shape); # good instance 
74
85
 
75
 
=item addExport(SWF::Block, name)
76
 
 
77
 
??? what this method is good for ???
78
 
 
79
 
=item remove(SWF::DisplayItem)
80
 
 
81
 
Removes the given instance from the current and following frames of the main timeline. 
 
86
=item $m->addExport($block, $name)
 
87
 
 
88
Prepare linkage to Action script code.
 
89
 
 
90
        $m->addExport($mc, 'mc');
 
91
        # and later inside action script....:
 
92
        $ac = new SWF::Action("_root.attachMovie('mc','mc1',11);");
 
93
 
 
94
=item $m->writeExports()
 
95
 
 
96
Export prepared names to Action script.
 
97
 
 
98
=item remove($displayItem)
 
99
 
 
100
Removes the given SWF::DisplayItem instance from the current and following frames of the main timeline. 
82
101
 
83
102
        $m->remove($shape_i);
84
103
 
85
104
=item nextFrame()
86
105
 
87
 
Finish a frame of the main timeline. New  added objects will be added in the next frame.
 
106
Finish a frame of the main timeline. New added objects will be added in the next frame.
88
107
 
89
108
        $m->nextFrame();
90
109
 
91
 
=item setFrames(int)
 
110
=item setNumberOfFrames($frames)
 
111
=item setFrames($frames)
92
112
 
93
113
Preset the number of frames of the main timeline. n not used frames before finishing the movie will filled with n nextFrame() statements.
94
114
If you inserted more nextFrame() commands than you set with setFrames() the setFrames() will be ignored. 
95
115
 
96
116
        $m->setFrames(100);
97
117
 
98
 
=item setBackground(red,green,blue)
 
118
=item $m->setBackground($red,$green,$blue)
99
119
 
100
120
Set the background in red, green, blue values. Possible value are 0..255 or hexvalues 0x0..0xff.
101
121
 
105
125
A transparency level isn't available I asume. (In Flash MX/F6?). A transparent background can be set in the HTML-code for Internet Explorer. Please 
106
126
inform the Authors if that is available for nonIE-browsers.
107
127
 
108
 
=item setDimension(x,y)
 
128
=item $m->namedAnchor($label)
 
129
 
 
130
This function adds a named anchor to the movie.
 
131
 
 
132
=item $m->setDimension(x,y)
109
133
 
110
134
Set the dimension in pixel.
111
135
 
112
 
        #We should implement this in ming c-lib!!
 
136
        #ToDo:
113
137
        #min: (0.0,0.0)   # ;-)
114
138
        #max: (?,?)
115
139
        #default: (0.0?,0.0?)
116
140
        #Behavior when values <min: ming sets it to min
117
141
        #Behavior when values >max: ming sets it to max
118
 
        
 
142
 
119
143
        $m->setDimension(200,100);
120
144
        $m->setDimension(123.45,67.89);
121
145
 
122
 
=item setRate(int)
 
146
=item $m->setRate(int)
123
147
 
124
148
Set the playing speed in frames/second. 
125
149
 
126
 
        #We should implement this in ming c-lib!!
 
150
        #ToDo:
127
151
        #min: 0
128
152
        #max: ?
129
153
        #default: ?
130
154
        #Behavior when value <min: ming sets it to min
131
155
        #Behavior when value >max: ming sets it to max
132
 
        
 
156
 
133
157
        $m->setRate(30);
134
158
 
135
 
=item protect()
 
159
=item $m->protect()
136
160
 
137
161
A feature that prevents only flashnewbies from importing your movie into Macromedias Flash authoring tools. It cannot protect your content from being loaded by 
138
162
other flashmovies, deleting of the protection with a hexeditor or disassembling with tools. 
139
163
 
140
 
        $m->protect();
141
 
 
142
 
=item setSoundStream(SWF::Sound)
143
 
 
144
 
Puts an SWF::Sound object as streaming sound into the main timeline.
145
 
 
146
 
        $m->setSoundStream($sound);
147
 
 
148
 
=item streamMp3(filename)
 
164
=item $m->setSoundStream($soundstream, [$skip])
 
165
 
 
166
Puts an SWF::SoundStream object as streaming sound into the main timeline.
 
167
The optional skip parameter describes the time in seconds to be skiped.
 
168
 
 
169
        $m->setSoundStream($soundstream);
 
170
 
 
171
=item $m->streamMp3($filename)
149
172
 
150
173
Simplifies the setSoundStream(). You only need the filename. 
151
174
 
152
 
        $m->("iloveyou.mp3");
153
 
 
154
 
Hint: If you want to reuse this sound/mp3 later in this movie, create a reusable SWF::Sound object and then put it into setSoundstream().
155
 
 
156
 
=item labelFrame(string)
 
175
        $m->streamMp3("iloveyou.mp3");
 
176
 
 
177
Hint: If you want to reuse this sound/mp3 later in this movie, create a reusable SWF::SoundStream object and then put it into setSoundstream().
 
178
 
 
179
=item $soundinstance = $m->startSound($sound)
 
180
 
 
181
Play a prepared SWF::Sound object into the main timeline. Returns an object of SWF::SoundInstance.
 
182
 
 
183
        $sound = new SWF::Sound("loveyoutoo.mp3", SWF_SOUND_MP3_COMPRESSED );  
 
184
        $si = $m->startSound($sound);
 
185
 
 
186
=item $m->stopSound($sound)
 
187
 
 
188
Stop playing sound.
 
189
 
 
190
=item $m->labelFrame($string)
157
191
 
158
192
Gives the current frame a label that can be used by actionscript as anchor. Then you don't have to count your nextFrame() lines anymore. :-)
159
193
 
160
194
        $m->labelFrame("win");
161
 
 
 
195
        #ToDo:
162
196
        #max characters of a label??? 
163
197
        #What happen if we put there a big string?? 
164
198
        #Which characters are allowed??
165
199
 
166
 
=item output([int compresslevel])
 
200
=item $m->setScriptLimits($maxRecursion, $timeout)
 
201
 
 
202
Set limits for resource usage, related to action script. Setting timeout will protect your computer from too long loops
 
203
and stack overflow. So endless scripts like "while (1){};" will be interrupted after timeout seconds.  The default 
 
204
recursion depth is 265, the default timeout is 15 seconds.
 
205
 
 
206
=item $m->defineScene($offset, $name)
 
207
 
 
208
Define scenes for the movies' main timeline using integer value for frame offset and name of the scene.
 
209
 
 
210
=item $m->setNetworkAccess($flag)
 
211
 
 
212
Sets network / fileaccess policy. If the flag is set to 0 a localy loaded 
 
213
movie will be unable to access the network but is allowed to access local files.
 
214
If the flag ist set to 1 a localy loaded movie will be unable to access local files
 
215
but is allowed to access the network. For SWF >= 8: default is 0,
 
216
 
 
217
=item $m->addMetadata($xml)
 
218
 
 
219
Adds Metadata to the movie: this function inserts a metadata-tag
 
220
into the movie. Only one metadata-tag can be set to a movie. 
 
221
Metadata is specified as an XML string. 
 
222
 
 
223
=item $m->assignSymbol($character, $name)
 
224
 
 
225
Assigns a symbolic name for a SWF::Character object.
 
226
Such classes are available for usage in other SWF files
 
227
and can be referenced from inside the current movie.
 
228
To assign a symbol to the root movie use NULL as character value.
 
229
 
 
230
=item $m->setTabIndex($depth, $index)
 
231
 
 
232
Sets tab index for specified depth level.
 
233
 
 
234
=item $fontchar = $m->addFont($font)
 
235
 
 
236
Adds a font to a movie. An object of SWF::FontCharacter class returned.
 
237
 
 
238
        $font = new SWF::Font('Arial.fdb');                                                                                                                                                                              
 
239
        $fch  = $m->addFont($font);      
 
240
 
 
241
=item $fontchar = $m->importFont($file, $name)
 
242
 
 
243
Imports a font from an other SWFFile. An object of SWF::FontCharacter class returned.
 
244
 
 
245
        $fch = $m->importFont('textField.swf', 'Arial337a'); 
 
246
 
 
247
=item $m->importCharacter($url, $name)
 
248
 
 
249
Not yet documented (ToDo!)
 
250
 
 
251
=item $result = $m->replace($item, $block)
 
252
 
 
253
This method replaces a displayable character with a new one.
 
254
Returns 0 on success , -1 else.
 
255
 
 
256
        $dispitem = $movie->add($shape1);
 
257
        $movie->nextFrame();
 
258
        print $movie->replace($dispitem, $shape2);
 
259
        $movie->nextFrame();
 
260
 
 
261
=item $written = $m->xs_output([$compresslevel])
 
262
 
 
263
=item $written = $m->output([$compresslevel])
167
264
 
168
265
Writes the SWF::Movie to stdout. This is normally used for webservers/cgi-scripts. 
169
266
Don't forget to send the "Content-Type:"-lines before writing out the movie.
170
267
 
171
268
The parameter compresslevel is optional. compresslevel between 0 and 9. Higher values will be interpreted as 9. Values smaller 0
172
269
mean no compression. By default the SWF::Movie will be send without compression. 
173
 
 
174
270
Notice: compression available since Flash MX(Flash 6). Ming does not check this for you if you write flash4 or flash5 movies.
175
271
 
176
 
=item save(filename [, int compresslevel]) 
177
 
        
178
 
Save the SWF::Movie to a file. 
179
 
 
 
272
Unlike xs_output() the output() method prepared for using via webservers (but not limited to webservers).
 
273
 
 
274
Both methods return number of bytes written.
 
275
 
 
276
=item $written = $m->save($filename [, $compresslevel]) 
 
277
 
 
278
Method saves the SWF::Movie to a file and returns the number of bytes written.
180
279
The parameter compresslevel is optional. compresslevel between 0 and 9. Higher values will be interpreted as 9. Values smaller 0 
181
280
mean no compression. By default the SWF::Movie will be saved without compression. 
182
 
 
183
281
Notice: compression available since Flash MX(Flash 6). Ming does not check this for you if you write flash4 or flash5 movies.
184
282
 
185
283
=back
194
292
 
195
293
        #!/usr/bin/perl -w
196
294
        use SWF::Movie;
197
 
        
 
295
 
198
296
        $m = new SWF::Movie();
199
297
        $m->nextFrame();
200
298
        $m->save("emptyminimal.swf");
203
301
 
204
302
        #!/usr/bin/perl -w
205
303
        use SWF::Movie;
206
 
        
 
304
 
207
305
        $m = new SWF::Movie();
208
306
        $m->setVersion(4);
209
307
        $m->setBackground(0xff,0xcc,0x0);
211
309
        $m->protect();
212
310
        $m->setRate(30);
213
311
        $m->setFrames(10); # ming fills it automatic with frames
214
 
        
 
312
 
215
313
        $m->nextFrame()
216
314
        $m->save("empty.swf");
217
315
 
218
316
=item streaming example
219
317
 
220
318
        #!/usr/bin/perl -w
221
 
        
222
319
        use SWF("Shape");
223
320
        SWF::setVersion(6);
224
 
        
 
321
 
225
322
        $m = new SWF::Movie();
226
323
        $m->setBackground(0xff,0xcc,0x0);
227
324
        $m->setDimension(200,100);
228
325
        $m->setFrames(10);
229
326
        $m->streamMp3("forever.mp3");
230
 
        
 
327
 
231
328
        $s= new SWF::Shape();
232
329
        $s->setLine(40,0xff,0xff,0);
233
330
        $s->setRightFill(0xff,0,0); 
234
331
        $s->drawLine(50,0);
235
332
        $s->drawLine(0,20);
236
333
        $s->drawLineTo(0,0);
237
 
        
 
334
 
238
335
        $s_1= $m->add($s);
239
336
        $s_2= $m->add($s);
240
337
        $s_1->move(50,40);
245
342
        }
246
343
        $m->nextFrame();
247
344
        print "Content-type: application/x-shockwave-flash\n\n";
248
 
 
249
345
        $m->output(9); # with compression level 9 (since flash6)
250
346
 
251
347
=back
252
348
 
253
349
=head1 AUTHOR
254
350
 
255
 
Soheil Seyfaie (soheil at users.sourceforge.net).
 
351
Soheil Seyfaie (soheil at users.sourceforge.net), Albrecht Kleine and
 
352
developers of ming.sourceforge.net
256
353
 
257
354
=head1 SEE ALSO
258
355
 
259
 
SWF, SWF::Action, SWF::Bitmap, SWF::Button, SWF::Constants, SWF::DisplayItem, SWF::Fill, SWF::Font, SWF::Gradient, SWF::Morph, SWF::Movie, SWF::Shape, SWF::Sound, SWF::Sprite, SWF::TextField, SWF::Text
 
356
SWF, SWF::Action, SWF::Bitmap, SWF::Button, SWF::Constants, SWF::DisplayItem, SWF::Fill, 
 
357
SWF::Font, SWF::FontCharacter, SWF::Gradient, SWF::Morph, SWF::MovieClip, SWF::Shape, 
 
358
SWF::PrebuiltClip, SWF::Sound, SWF::SoundStream, SWF::TextField, SWF::Text, SWF::Filter, SWF::Character
260
359
 
261
360
=cut