actionscript 3 - How do I control a movieclip using a button? -
actionscript newbie. actionscript 3.0 started following tutorial @ http://republicofcode.com/tutorials/flash/basicwebsite/ works fine long code remains in flash file. when move external file have issue.
i have following code on action layer keyframe:
stop(); function gohome (e:mouseevent):void{ gotoandstop("home"); } home_btn.addeventlistener(mouseevent.click, gohome); function goabout (e:mouseevent):void{ gotoandstop("about"); } about_btn.addeventlistener(mouseevent.click, goabout); function golinks (e:mouseevent):void{ gotoandstop("links"); } links_btn.addeventlistener(mouseevent.click, golinks); function gocontact (e:mouseevent):void{ gotoandstop("contact"); } contact_btn.addeventlistener(mouseevent.click, gocontact);
everything works fine want move code external as3 file , running issues.
i have added document class "site1" , name of external file. removed code flash file keyframe , moved external file.
here code appears in site1.as
package { import flash.display.movieclip; import flash.events.mouseevent; import flash.text.textfield; public class button extends movieclip{ public function button() { function gohome (e:mouseevent):void{ gotoandstop("home"); } home_btn.addeventlistener(mouseevent.click, gohome); function goabout (e:mouseevent):void{ gotoandstop("about"); } about_btn.addeventlistener(mouseevent.click, goabout); function golinks (e:mouseevent):void{ gotoandstop("links"); } links_btn.addeventlistener(mouseevent.click, golinks); function gocontact (e:mouseevent):void{ gotoandstop("contact"); } contact_btn.addeventlistener(mouseevent.click, gocontact); } } }
the problem when publish flash file keeps looping , not pausing button click.
any @ appreciated.
name class , file same name. suggest following code.
package { import flash.display.movieclip; import flash.events.mouseevent; import flash.text.textfield; public class yourclassname extends movieclip { public function yourclassname() { home_btn.addeventlistener(mouseevent.click, gohome); about_btn.addeventlistener(mouseevent.click, goabout); links_btn.addeventlistener(mouseevent.click, golinks); contact_btn.addeventlistener(mouseevent.click, gocontact); } private function gohome(e:mouseevent):void { gotoandstop("home"); } private function goabout(e:mouseevent):void { gotoandstop("about"); } private function golinks(e:mouseevent):void { gotoandstop("links"); } private function gocontact(e:mouseevent):void { gotoandstop("contact"); } } }
as3 more explicit as2. suggest use private
/ public
accessors.
edit.
'button' not class name, work.
1) name file, class , constructor : 'button' :
public class button extends movieclip public function button()
2) sure linkage good! meaning : if want control whole movie class, change document "class" name button
, if want control movieclip library, drag on stage, check "export action script", , change "class" value button
.
think method, don't need instance name. class linkage enough in case.
ref :
http://help.adobe.com/en_us/flashplatform/reference/actionscript/3/class.html
Comments
Post a Comment