![]() |
![]() |
||||||
|
|||||||
| Tags: |
![]() |
|
|||
|
Greetings,
Been experimenting with AS3 here. I've created a project with a Document Class named "Main" and only a single MC in it named "Button_MC" and linkage. Inside that Button_MC, I have a timeline with a couple of stop()'s for some animation. Here's my code (Main.as): package { import flash.display.MovieClip; import flash.events.*; public class Main extends MovieClip { // put main vars here // Constructor public function Main() { // put add on stage stuff here var button1:QuickButton = new QuickButton("Click Me"); addChild(button1); button1.x = 100; button1.y = 100; button1.addEventListener(MouseEvent.CLICK, onClick); button1.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver); } private function onClick(e:Event):void { trace("hi"); } private function onMouseOver(e:Event):void { //button1.play(); } } } Also here's my (QuickButton.as) too: package { import flash.display.*; import flash.events.*; import flash.text.*; public class QuickButton extends MovieClip { public function QuickButton(myText:String):void { // put in the button var btn:Button_MC = new Button_MC(); btn.buttonMode = true; //btn.useHandCursor = true; addChild(btn); // put in the text feild var tf:TextField = new TextField(); var format:TextFormat = new TextFormat(); format.font = "Verdana"; format.color = 0x000000; format.size = 12; format.align = "center"; tf.defaultTextFormat = format; tf.selectable = false; tf.text = myText; tf.width = 100; btn.addChild(tf); } } } So my AS3 places a single instance of "button1" on my stage. How do I access this to play it's animation? button1.gotoAndPlay(2) will not work? thanks -richard |
| Sponsored Links |
|
|||
|
kglad wrote:
> that should work if used in Main and if you want a reference accessible on your main timeline, pass one, for example, using a getter. Greetings kglad, The problem actually is.. that I can't get the timeline of my MC created in flash, to play.. If you notice here: --- private function onMouseOver(e:Event):void { button1.play(); } --- So, I tried some defferent angles.. I tried moving my "play()" to QuickButton.as as a function. I tried 1) this.play(); // won't play 2) btn.play(); // won't play 3) gotAndPlay(2); // won't play 4) this.gotoAndPlay(2); //won't play 5) btn.gotoAndPlay(2); // won't play 6) gotoAndPlay(2); // won't play.. I create a Movie Clip in the Library. I named it "Button_MC". Linked it. Instantiated it inside QuickButton.as like this... var btn:Button_MC = new Button_MC(); but I can't get it to play the time line? I also tried to label it too.. I'm thinking this is a bug, and perhaps documented right here.. http://www.scottgmorgan.com/blog/ind...r-gotoandplay/ Bummer.. -Richard |
|
|||
|
kglad wrote:
> that's not a bug. that's an unsophisticated flash user that's failed to understand the render sequence in as3. > > are you trying to reference an object in frame after a goto or play method? No, I guess your right. I'm just trying to get a MC (created in Flash in the Library) timeline to play from using AS3. -Richard |
|
|||
|
Richard Ragon wrote:
> kglad wrote: >> that's not a bug. that's an unsophisticated flash user that's failed >> to understand the render sequence in as3. >> >> are you trying to reference an object in frame after a goto or play >> method? > > No, I guess your right. > > I'm just trying to get a MC (created in Flash in the Library) timeline > to play from using AS3. > > -Richard Well.. Day 3 now, of just trying to get a MC to play an animation time line using AS3. So, I decided to dedicate all my free time on this bug now.. So, I striped down a simple project, just to illustrate the problem. 1) Create a .fla file. 2) Create a MovieClip manually and name it "Box", and place it in the Library. On the timeline of this MC, it has a stop(), 10 frames of some animation, and it goes back to the stop() again. 3) Name the Document Class "Timeline". 4) Create a new .as file, call it "Timeline.as" 5) Copy this text into it. --- cut --- package { import flash.display.*; import flash.events.*; public class Timeline extends MovieClip { public function Timeline():void { var myBox:Box = new Box(); myBox.y = 100; myBox.x = 100; myBox.addEventListener(MouseEvent.ROLL_OVER,move_b ox); this.addChild(myBox); } private function move_box(e:Event):void { myBox.play(2); // this fails??? don't know why }; } //class } // package --- end --- No matter what.. I can NOT get the myBox MC to play it's animation?? The funny thing is.. It works if you get rid of this document class, and place all the AS3 on the frame instead.. But, I'm trying to learn AS3, doing it the right way using document classes with AS3 all on the outside.. I can see why people are just not going to move to AS3, from AS2. Days and days of trying to just do simply crap, like play a timeline.. I've also found some discussions on the matter too.. http://www.actionscript.org/forums/a.../t-140171.html Thanks -Richard |
|
|||
|
there's no bug. there's are coder errors, though.
1. you made myBox local to the constructor so it's not available in the class: the var and declare myBox as a class variable. 2. there's no argument in the play() method. use gotoAndPlay() if you want to direct the timeline to a particular frame. (though in your case, play() is adequate.) |
|
|||
|
kglad wrote:
> there's no bug. there's are coder errors, though. Ok, > 1. you made myBox local to the constructor so it's not available in the > class: the var and declare myBox as a class variable. Lost me here?? > 2. there's no argument in the play() method. use gotoAndPlay() if you want > to direct the timeline to a particular frame. (though in your case, play() is > adequate.) gotoAndPlay() will be used on the final project.. I just used play() as a quick example. -Rich |
|
|||
|
kglad wrote:
> 1.: > > package { > import flash.display.*; > import flash.events.*; > > public class Timeline extends MovieClip { > var myBox:Box; > public function Timeline():void { > > myBox = new Box(); Am, I missing something here? This is exactly what I have in my example that I gave you??? -rich |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise