#!/usr/bin/perl # # Example 9-10. The client. use SWF qw(:ALL); use SWF::TextField qw(:Text); SWF::useSWFVersion(5); # Create a new Movie my $m = new SWF::Movie; $m->setDimension(400,400); # ActionScript for intializing the XMLSocket object that # handles all of our communication and XML parsing needs $m->add(new SWF::Action(<nextFrame(); # Create a TextField for displaying messages my $font = new SWF::Font("serif.fdb"); my $tf = new SWF::TextField(SWFTEXTFIELD_DRAWBOX| SWFTEXTFIELD_MULTILINE| SWFTEXTFIELD_WORDWRAP); $tf->setFont($font); $tf->setColor(0,0,0); $tf->setName("chatwindow"); $tf->setHeight(10); $tf->setBounds(300,260); my $item = $m->add($tf); $item->moveTo(0,10); # Create a TextField for holding the chatter's handle my $tf2 = new SWF::TextField(SWFTEXTFIELD_DRAWBOX); $tf2->setFont($font); $tf2->setColor(0,0,0); $tf2->setHeight(10); $tf2->setName("handle"); $tf2->addString("Mr. Foo"); $tf2->setBounds(50,10); $item = $m->add($tf2); $item->moveTo(0,280); # A TextField for entering new messages my $tf3 = new SWF::TextField(SWFTEXTFIELD_DRAWBOX); $tf3->setFont($font); $tf3->setColor(0,0,0); $tf3->setHeight(10); $tf3->setName("message"); $tf3->setBounds(200,10); $item = $m->add($tf3); $item->moveTo(50,280); # Create a 'submit' button my $s = new SWF::Shape(); $s->setLineStyle(1, 0, 0, 0); # Black stroke $s->setLeftFill($s->addFill(255, 255, 255)); $s->drawLine(35, 0); $s->drawLine(0, 10); $s->drawLine(-35, 0); $s->drawLine(0, -10); my $t = new SWF::Text(); $t->setFont($font); $t->setColor(0, 0, 0); $t->setHeight(10); $t->addString("SUBMIT"); $item = $m->add($t); $item->moveTo(260,290); # Add the action script that sends the message and handle as # XML to the chat server my $b = new SWF::Button(); $b->addShape($s, SWF::Button::SWFBUTTON_HIT); $item = $m->add($b); $item->setName("button1"); $b->setAction(new SWF::Action(<moveTo(260,280); $m->nextFrame(); # Loop $m->add(new SWF::Action(<nextFrame(); $m->save('chatclient.swf'); exit();