Copy link to clipboard
Copied
Hey Everybody,
I am working on an INCREDIBLY simple flash video display in CS4 with AS3. I have a 6-second video clip with no sound. The only control I want on it is a "replay" button. The video instance name is "lakerise" and the button name is "playbtn". The code is below.
I am wondering if the problem here is something not in the script itself (like button properties?), but I'm not really sure. I set the "autoplay" property for the video to "true," so the movie plays once and the button shows up, but then is unresponsive. The mouse changes to the hand over the button, so it seems to recognize the symbol. At this point, I get no compiler errors.
Other things I have tried were:
*adding an event listener to stop or pause the video after it finishes
*starting the code with stop();
*removing one or two of the commands in the repeat function in various combinations (just doing "seek(0)" or just doing "play()"
Let me know if you have any ideas about how to fix this! Also, I apologize if I made any forum faux pas. Thanks!
import fl.video.*;
var lakerise:FLVPlayback = new FLVPlayback();
var playbtn:SimpleButton = new SimpleButton();
playbtn.addEventListener(MouseEvent.CLICK, repeat);
function repeat(event:MouseEvent):void {
lakerise.pause();
lakerise.seek(0);
lakerise.play();
}
Copy link to clipboard
Copied
SimpleButton is a base class. Where are you adding it to the display list?
Also try to keep your function names far separated from built-in functon/method/component definitions. e.g. no functions named play(), stop(), repeat(), etc.. Something descriptive keeps the compiler on the same page as you, like repeatMyVideo() rather than repeat() (although I don't believe this is your issue).
Copy link to clipboard
Copied
I'm not sure. What is the display list?
First I added it as "Button" instead of "SimpleButton" and I believe an error popped up that "Button" was no longer supported in AS3 or something. Is there another base class I should be using, and might that clear up the issue?
Didn't realize repeat() was already defined but I'll change it. I think I called it repeate so as not to name "replay" thinking that would be likely defined. Guess not!
Copy link to clipboard
Copied
On the first item, SimpleButton is in fact the same a the class if you went into the IDE and converted your selection to a "Button". So you're correct in using that class if you want a button. However Sprite/MovieClip both retain the same mouse functionality on click and can easily be coded on roll so you might consider using the slim "Sprite" class instead.
e.g.
var a:Sprite = new Sprite();
// This is what I mean by add to display list
addChild(a);
// create shape using graphics methods
a.graphics.beginFill(0xFF0000,1); // red
a.graphics.drawRect(200,50); // 200w x 50h
a.graphics.endFill();
// add a click listener
a.addEventListener(MouseEvent.CLICK, onClickAF);
function onClickAF(e:MouseEvent):void
{
trace("You clicked A");
}
It's pretty easy to make a button. To make a roll state you'd add some extra code drawing more into the "a" clip as a roll state and then turning it on/off based on MouseEvent ROLL_OVER and ROLL_OUT. You'd just turn the .visible property true or false on your custom roll graphics.
As far as repeat, I don't recall it being a base function, it serves as a general shot across the bow to make sure you're not overriding base functions. Keep your function names "obviously" unique to avoid this.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now