File Coverage

blib/lib/SWF/Builder/Character/MovieClip.pm
Criterion Covered Total %
statement 53 61 86.8
branch 3 6 50.0
condition 0 6 0.0
subroutine 13 14 92.8
pod 1 1 100.0
total 70 88 79.5


line stmt bran cond sub pod time code
1             package SWF::Builder::Character::MovieClip;
2              
3 1     1   5 use strict;
  1         2  
  1         35  
4 1     1   930 use utf8;
  1         10  
  1         14  
5              
6 1     1   34 use Carp;
  1         1  
  1         82  
7 1     1   7 use SWF::Element;
  1         2  
  1         22  
8 1     1   6 use SWF::Builder;
  1         2  
  1         23  
9              
10 1     1   6 use Carp;
  1         1  
  1         455  
11              
12             our $VERSION='0.05';
13              
14             @SWF::Builder::Character::MovieClip::ISA = ('SWF::Builder::Character::Displayable');
15              
16             sub place {
17 1     1 1 12 my $self = shift;
18              
19 1         10 bless $self->SUPER::place(@_), 'SWF::Builder::DisplayInstance::MovieClip';
20             }
21              
22             ####
23              
24             @SWF::Builder::Character::MovieClip::Imported::ISA = qw/ SWF::Builder::Character::Imported SWF::Builder::Character::MovieClip /;
25              
26             ####
27              
28             package SWF::Builder::Character::MovieClip::Def;
29              
30             @SWF::Builder::Character::MovieClip::Def::ISA = qw/ SWF::Builder::Movie SWF::Builder::Character::MovieClip /;
31              
32             sub new {
33 1     1   9 my $self = shift->SUPER::new;
34 1         3 $self->{_init_action} = undef;
35 1         16 $self->_init_character;
36 1         9 $self;
37             }
38              
39             sub _pack {
40 1     1   3 my ($self, $stream) = @_;
41              
42 1         14 $self->set_depth;
43 1         22 SWF::Builder::DefineSprite->new
44             ( SpriteID => $self->{ID},
45 1         3 FrameCount => scalar(@{$self->{_frame_list}}),
46             ControlTags => $self->{_frame_list}
47             )->pack($stream);
48 1 50       407 if ($self->{_init_action}) {
49 0         0 my $tag = SWF::Element::Tag::DoInitAction->new;
50 0         0 $tag->SpriteID($self->{ID});
51 0         0 $tag->Actions($self->{_init_action}{_actions});
52 0         0 $tag->pack($stream);
53             }
54             }
55              
56             sub init_action {
57 0     0   0 require SWF::Builder::ActionScript;
58 0         0 my $self = shift;
59              
60 0         0 $self->{_root}->_depends($self, 1);
61 0   0     0 $self->{_init_action} ||= SWF::Builder::ActionScript->new(Version => $self->{_root}{_version});
62             }
63              
64             sub _destroy {
65 1     1   3 my $self = shift;
66 1         9 $self->SWF::Builder::Movie::_destroy;
67 1         15 $self->SWF::Builder::Character::Displayable::_destroy;
68             }
69              
70             @SWF::Builder::DefineSprite::ISA = qw/ SWF::Element::Tag::DefineSprite /;
71              
72             sub SWF::Builder::DefineSprite::_pack {
73 1     1   180 my ($self, $stream) = @_;
74 1         5 $self->SpriteID->pack($stream);
75 1         46 $stream->set_UI16(scalar @{$self->ControlTags});
  1         4  
76 1         38 $self->ControlTags->pack($stream);
77             }
78              
79             #####
80              
81             package SWF::Builder::DisplayInstance::MovieClip;
82              
83 1     1   4 use Carp;
  1         2  
  1         334  
84              
85             @SWF::Builder::DisplayInstance::MovieClip::ISA = qw/ SWF::Builder::DisplayInstance /;
86              
87             my %special_keys = (
88             '' => 1,
89             '' => 2,
90             '' => 3,
91             '' => 4,
92             '' => 5,
93             '' => 8,
94             '' => 6,
95             '' => 13,
96             '' => 14,
97             '' => 15,
98             '' => 16,
99             '' => 17,
100             '' => 18,
101             '' => 19, # ? don't work.
102             '' => 32,
103             );
104              
105             sub on {
106 1     1   860 require SWF::Builder::ActionScript;
107            
108 1         177 my ($self, $event, $key) = @_;
109 1         9 my $clipactions = $self->{_tags}[0]{_tag}->ClipActions;
110 1         43 my $newaction = $clipactions->new_element;
111 1         25 my $eventsub = "ClipEvent$event";
112            
113 1         2 eval{$newaction->$eventsub(1)};
  1         5  
114 1 50       26 croak "$event is not a valid clip action event" if $@;
115 1         3 push @$clipactions, $newaction;
116 1 50 0     4 $newaction->KeyCode($special_keys{$key} || ord($key)) if $event eq 'KeyPress';
117 1         8 my $action = SWF::Builder::ActionScript->new(Version => $self->{_root}{_version});
118 1         28 $newaction->Actions($action->{_actions});
119 1         15 return $action;
120             }
121              
122             *onClipEvent = \&on;
123              
124             #####
125              
126             1;
127             __END__