Making movie clips play in reverse in AS 3.0

Hey all. I'm changing all my files to AS 3.0 because of some
new elements I'd like to use in flash CS4.
Here:
http://www.iaw-atlanta.com/IvyLeague1-13-09.html
I have the menu navigation at the bottom with 4 buttons. When the
buttons are moused over they ascend and when they are moused out
the movie plays in reverse so that they descend. Basically in the
movie clip, I have it stopped as well as gotoAndPlay the next frame
when the button is moused over and then have a script telling it to
reverse when moused out. I know how to do this in AS 2.0 but how
can I translate the script to 3.0?

DjPhantasy5,
> Ok thanks, I'll see what he also has to say as well.
Actually, NedWebs pretty much nailed it. :) The approach
you've taken
is an interesting one, because it scales all the way back to
Flash Player 5,
which didn't yet support the MovieClip.onEnterFrame event.
Without that
event, you need something like your "controller" symbol -- a
separate
looping timeline -- to perform code that depends on frame
loops.
Available as of Flash Player 6, that event would allow you
to
consolidate your code a bit by putting it all in a single
frame and avoiding
the extra movie clip symbol. That doesn't mean your approach
is wrong, by
any stretch. In fact, it's good to know your options, because
if you ever
need to publish to Flash Player 5, you'll probably do best to
use the setup
you've taken.
I'll demonstrate onEnterFrame in just a bit, in case you
want to take a
look at that.
>> there's no _root reference in AS3, but you can use a
>> MovieClip(this.parent) (which replaces what _parent
>> used to do) to locate something outside of the
immediate
>> movieclip.
The term "parent," in this context, is technically a
property of the
MovieClip class, which means all movie clips in AS3 have
access to the
"parent" feature, which points to the timeline that contains
the movie clip
in question. Buttons also feature a "parent" property. In
AS2, this
property acted exactly the same, only it was preceeded by an
underscore.
In fact, NedWebs' suggested code works the same in your
existin file.
Instead of this:
// Your existing code ...
if (_root.animation._currentframe>1) {
_root.animation.prevFrame();
this.gotoAndPlay(2)
if (_root.animation._currentframe<=1) {
this.gotoAndStop(1);
... you could be using this:
// Alternative code ...
if (_parent.animation._currentframe>1) {
_parent.animation.prevFrame();
gotoAndPlay(2)
if (_parent.animation._currentframe<=1) {
gotoAndStop(1);
... because from this scope -- that is, from this point of
view -- the
MovieClip._parent property points to the same timeline that
_root does.
That changes, of course, based on how deeply nested the
current scope is.
The term "this" in the above code is optional, because Flash
understands
what scope you're in. From the point of view of this code,
_parent is
understood to refer to the current scope's parent timeline,
just like
gotoAndPlay() is understood to refer to the current scope's
own timeline.
You could precede either of those by "this" or not.
Many people will argue that _root is probably best avoided,
only because
it's a slippery slope. It doesn't always refer to the main
timeline you
think it does, depending on whether or not your SWF is loaded
into another
SWF at runtime. Meanwhile, _parent *always* refers to the
immediately
parent timeline.
So when you look at it that way, this perfectly valid AS2:
if (_parent.animation._currentframe>1) {
... isn't much different at all from its AS3 counterpart:
if (MovieClip(parent).animation.currentFrame>1) {
It would be nicer if you didn't need to cast the parent
reference as a
movie clip here, but if you don't, AS3 doesn't realize that
the scope in
question is a movie clip.
>> You can string them along as...
>> MovieClip(this.parent.parent)
Exactly.
>> Your _currentframe in the the controller becomes
>> currentFrame. That's about it. The rest of what I
>> saw will fly as is.
Not quite. AS3 doesn't support the on() or onClipEvent()
functions, so
you won't be able to attach your code direction to the
button. Instead,
you'll have to put it in a keyframe -- which you can also do
with AS2. It's
a good idea, in any case, because it allows you to put all
your code in one
place, making it easier to find.
Here's a quick note on direct attachment:
http://www.quip.net/blog/2006/flash/museum-pieces-on-and-onclipevent
To convert your existing FLA structure to AS3, you might,
for example,
do this:
animation.buttonMode = true;
animation.addEventListener(MouseEvent.ROLL_OUT, outHandler);
animation.addEventListener(MouseEvent.ROLL_OVER,
overHandler);
function outHandler(evt:MouseEvent):void {
controller.gotoAndPlay(2);
function overHandler(evt:MouseEvent):void {
controller.gotoAndPlay(4);
That takes care of the on(rollout) and on(rollover) code in
your current
version. The first line (buttonMode) is only necessary
because I got rid of
the button symbol and, instead, associated the event handlers
directly with
your animation clip. (Movie clips handle button-style events,
too, so you
don't need the button.) In AS3, event handling is very
straightforward:
you reference the object (here, animation), invoke its
inherited
addEventListener() method, then pass in two parameters: a)
the event to
listen for, and b) the function to perform when that event
occurs.
You can see that spelled out above. In AS2, there are quite
a few ways
to handle events, including on()/onClipEvent(), so it's
harder to know when
to use what approach. For buttons and movie clips, the
princple works the
same as I just showed, but the syntax is different.
Let's take a quick look at reducing all this code by using
the
onEnterFrame event. First, check out this AS2 version:
animation.onRollOut = outHandler;
animation.onRollOver = overHandler;
function outHandler():Void {
this.onEnterFrame = reversePlay;
function overHandler():Void {
this.onEnterFrame = null;
this.play();
function reversePlay():Void {
this.prevFrame();
All of that code would appear in frame 1. You don't need the
controller
movie clip. The animation clip no longer contains an orb
button, because
we're using animation itself as the "button". (You can always
see what
functionality any object has by looking up its class. If
you're dealing
with a movie clip, look up the MovieClip class. See the
Properties heading
to find out what characteristics the object has, see Methods
to find out
what the object can do, and see Events to find out what the
object can react
to.)
In the above code, it's all laid out pretty easily. This is
AS2,
remember. We have two events we're listening for:
MovieClip.onRollOut and
MovieClip.onRollOver. Those events are established for the
animation movie
clip by way of its instance name, and associated with
corresponding custom
functions. The outHandler() function associates yet another
function to the
MovieClip.onEnterFrame event of the animation clip. Very
simply, it
instructs animation to perform the custom reversePlay()
function every time
it encounters an onEnterFrame event. The overHandler()
function kills that
association by nulling it out, and telling animation to play,
via the
MovieClip.play() method. Finally, the reversePlay() function
simply invokes
MovieClip.prevFrame() on the animation clip.
Here's the AS3 version:
animation.buttonMode = true;
animation.addEventListener(MouseEvent.ROLL_OUT, outHandler);
animation.addEventListener(MouseEvent.ROLL_OVER,
overHandler);
function outHandler(evt:MouseEvent):void {
animation.addEventListener(Event.ENTER_FRAME, reversePlay);
function overHandler(evt:MouseEvent):void {
animation.removeEventListener(Event.ENTER_FRAME,
reversePlay);
animation.play();
function reversePlay(evt:Event):void {
evt.target.prevFrame();
It looks wordier, but if you look carefully, you'll see that
it's
essentially the same thing. The main difference is the way
scope works in
AS3. In AS2, there are numerous references to "this", because
the event
handler functions operate in the same scope as the object to
which the
association is made. In AS3, the references aren't to "this",
but rather to
the same animation clip by its *intance name*, because in
AS3, the scope
operates in the same timeline in which the code appears
(namely, in this
case, the main timeline).
In the reversePlay() function, in order to emulate a "this"
sort of
setup, I'm referring to the parameter that gets passed to all
event handler
functions in AS3. I happened to name it "evt" (for event),
but you can call
it what you like. In the case of reversePlay(), the evt
parameter refers to
an instance of the Event class, which has a target property.
The target
property refers to the object that dispatched the event --
happens to be
animation, in this case. So evt.target, in this context,
refers to
animation, which is what I invoke the MovieClip.prevFrame()
method on.
I've uploaded a handful of FLA files to my server. I won't
keep them
there forever ... maybe a couple weeks, as of this post:
http://www.quip.net/RewindTestAS3.fla
http://www.quip.net/RewindTestAS3_new.fla
http://www.quip.net/RewindTestAS2_new.fla
David Stiller
Co-author, ActionScript 3.0 Quick Reference Guide
http://tinyurl.com/2s28a5
"Luck is the residue of good design."

Similar Messages

  • How do I make a movie clip play between scenes?

    I am VERYnew to flash so please bear with me. I am having a
    problem with a movie clip playing between scenes. As scene 1 plays,
    the movie works correctly. When I click on my button to go to scene
    2 the movie clip starts over. I would like it to continue from
    scene 1 seamlessly. Is this possible? How do I do it?

    avoid scenes - they are only for timeline management inside
    flash only - upon export it all becomes
    one long timeline - using them can be useful but in many
    instances it can cause navigational issues
    such as yours. Many developers avoid scenes - the ones who
    use them are mostly animators who have
    longer timelines with different scenes (actual settings, like
    backgrounds and characters).
    --> Adobe Certified Expert (ACE)
    --> www.mudbubble.com :: www.keyframer.com
    -->
    http://flashmx2004.com/forums/index.php?
    -->
    http://www.macromedia.com/devnet/flash/articles/animation_guide.html
    -->
    http://groups.google.com/advanced_group_search?q=group:*flash*&hl=en&lr=&ie=UTF-8&oe=UTF-8
    Maureen Getchell wrote:
    > I am VERYnew to flash so please bear with me. I am
    having a problem with a
    > movie clip playing between scenes. As scene 1 plays, the
    movie works correctly.
    > When I click on my button to go to scene 2 the movie
    clip starts over. I would
    > like it to continue from scene 1 seamlessly. Is this
    possible? How do I do it?
    >

  • Making a movie clip play beyond keyframe

    Hi,
    I have a movie clip that is about 30 frames long. I've placed an instance of it on the main timeline and it follows a motion path. My motion path ends after about 20 frames. At this time, I've inserted a keyframe which is preventing my movie clip from playing the remaining 10 frames.
    I tried adding an ActionScript layer where the last keyframe is and it reads:
    instance.gotoAndPlay (20)
    Doesn't seem to work. Just a note that this is around frame 292 of the main timeline. Also note, a new keyframe begins on another layer with a different movie clip.
    Any ideas? Much appreciated.

    I think I may understand now, and your first approach to solving it should work.  What you need to be sure to do is to assign the instance name at every keyframe.  If you did not name it in its first frame of the main timeline, it will inherit that lack of a name in the keyframe at the end of the tween, regardless of your assigning it there... just a quirk of Flash.
    Another option, if this is a straight line tween of the object on the main timeline is to use actionscript to animate it rather than a timeline tween.

  • How do i have clips play in reverse

    I need help! How do u make the clips in your movie play in reverse and the music play forward HELP!!!!!!!!!!!!!!!!!!!!!

    'Search' is your friend..
    read reply on same topic here..
    http://discussions.apple.com/click.jspa?searchID=10830738&messageID=7320531
    .. and please avoid double posts.. http://discussions.apple.com/thread.jspa?threadID=1550375&tstart=0

  • Movie Clip playing very fast

    Hi guys,
         I have a problem with my loaded movie clip, its playing very fast than its suppose to, (using loadMovie) I've tried to adjust the frame rate of the main file and the movie file, but still the problem occurs.... any suggestion on fixing this??

    If both movies do not have the same frame rate, then they need to be the same.

  • How do you make a movie clip play in CS4

    Hello, I used Flash MX a long time ago (beginner level) then
    left it for years. I'm now using CS4 and am stuck. I have a stage
    with a movie clip placed onto it. I want to create a simple 'click
    to play' button so that the movie clip only plays on click of this
    button. Can someone please give me a step by step (idiot-proof)
    guide on how to do this please

    Cases that use to be _property in AS2 are now just property
    in AS3. So _x is x, _y is y, and _visible is visible. This should
    work:
    function showPlay(event:MouseEvent):void
    play_text.visible = true;
    pause_text.visible = false;

  • Make a clip play in reverse?

    I can't find it on the website...I have this SUPER funny fall of this person...why we all laugh at that?....WELL I want to have the person fall, and then all of a sudden he is played in reverse, and then fall again, etc, back and forth....
    I know how to pause it, and slow motion it, mirror it, etc, but I want that reverse and back down again....I'm sure it is possible and easy???
    Any insight would be GREATLY appreciated...and will post the youtube link as soon as I finish it!
    Thanks,
    Dan

    when you have the clip selected in the sequence, take the razor blade tool and cut the clip at where you want the reverse to begin. then, delete the rest of the clip after it, and insert a copy of the clip that you want reversed. select the copy, then click Modify>Speed. when the window comes up, just check the "reverse" box, and click ok.
    Hoped that helped.

  • Movie clip plays onRollover?

    When someone rolls over a button, I would like it to play a
    movie clip.
    I place the movie clip on the rollover state though it is not
    working.
    1. Am I doing this right?
    2. What if I want the movie clip to play somewhere else on
    the stage.
    How do I position the movie clip while in button edit mode so
    it is in
    the location I want it to be when it is actually placed on
    the stage?
    Thanks.

    dave wrote:
    > When someone rolls over a button, I would like it to
    play a movie clip.
    > I place the movie clip on the rollover state though it
    is not working.
    >
    > 1. Am I doing this right?
    Not really the right way. Tho, You can place movie clip in
    over state of the
    button but then you have no control over it as the states
    reset as soon as you
    move the mouse out of the HIT area. You need to place the
    clip outside of the
    button, give it instance name and target that instance name
    using button handlers,
    like on roll over or on press.
    > 2. What if I want the movie clip to play somewhere else
    on the stage.
    > How do I position the movie clip while in button edit
    mode so it is in
    > the location I want it to be when it is actually placed
    on the stage?
    button with instance name myBtn and movie clip with instance
    name myMovie.
    On timeline frame following action:
    myBtn.onRollover = function(){
    myMovie.play();
    Best Regards
    Urami
    "Never play Leap-Frog with a Unicorn."
    <urami>
    If you want to mail me - DO NOT LAUGH AT MY ADDRESS
    </urami>

  • How do I have the same clip playing in reverse and forwards

    So essentially when I try to reverse one clip of two of the same clips it reverses both of them instead of just the one I selected. I've tried renaming it too and it didn't work. Thanks so much for your answers!

    This happens because multitrack mode in Audition is essentially a very posh file player. If you have a file that plays in one direction, then it's simply not possible for the same file to play backwards at the same time - the engine can't do that! When you think you're playing two separate clips, you almost certainly aren't - this is just two playback instances of essentially the same file/clip.
    There is a simple solution though; create a second (physically unique) copy of the clip and place that as the reversed one. Then you can have one clip playing in one direction, and the other clip playing in the opposite one.

  • Controlling movie clip play order

    Good Day,
    I have a web site that opens with two movie clips. One (A)
    folds open some navigation menus, the other (B) opens some
    rectangles that hold content. I want "A" to play out then, once it
    is played, I want "B' to start. It sounds simple but I cannot get
    the right code. I need something I can use for other applications
    in other pages. I have this code so far; (naigation_mc = "A"
    page01_mc = "B")
    if (navigation_mc.play=true) {
    page01_mc.gotoAndStop("start");
    } else {
    page01_mc.gotoAndPlay("start");
    Perhaps there needs to be more code to controll this?

    The most likely cause for you problem lies in the scope of
    "this" in your case.
    While traitional flash5 style buttons would have the imeline
    in which they reside (e. g. the main timeline) as scope and a
    comand like
    on (release){
    stop();
    wouls stop he playhead of the main timeline.
    Where as the more modern form of attaching code to a button
    and the explicit use of
    this handles buttons like movieClips so that a command like:
    myButton.onRelease = function(){
    this.stop();
    will try to stop the buttons (= movieclips) own timeline.
    I hope that helps
    [This fact isn't stated clearly in the docs, but I at least
    asked Macromedia (back then) to add it at least to the live
    docs.]

  • Movie Clip "Play" problem

    Dear all
    I have a singl movie clip which has an embedded video inside.
    I use the following actionscript commands to stop and play it
    onClipEvent(load) {
    stop();
    onClipEvent(mouseDown) {
    play(); }
    onClipEvent(mouseUp) {
    stop(); }
    The problem I face is that the movie clip should play when
    clicked by mouse ONLY on movie clip area which occupies only a
    small part of the stage. However, when I click the mouse ANYWHERE
    on the stage the movie starts to play.
    Any hint? Do I need to control the coordinates of the mouse ?
    Thanks
    Hagop

    sorry, I made a mistake- i had not re-saved my files, so it
    worked but not the way i thought...
    my code, based on your response is attached- however it
    doesnt work...
    mcOther is a mc within the "child" - other.swf.
    this code needs to be in the "parent" swf...
    thank you.

  • Movie clip plays then stops will not start

    I downloaded this clip from the internet. It plays fine(HD) then it stops. I can advance fram by fram only.
    please help.

    First try to restart without extentions to see if you can just copy manually the informations onto a disk or extern HD.
    If this won't help you can try DATA rescue II . You may be able to get a part of your docs back, but this can take a while... between a day and a month...

  • Playing a movie clip in a simgle frame

    I'm making a flash gallery of several different animations,
    each being in one movie clip. I was wondering if there's a way to
    make a whole, say, 1000 frame movie clip play in a single frame on
    the main timelime, and how it would be done. (assuming that the
    main timeline frame has the actionscript to make the movie stop)
    I'm kinda new to actionscript and all, even though I've been
    working with flash for a while, so it would be a real big help for
    this project and future ones.
    -EDIT-
    I'm using AS2 for this project.

    It helps to realize that even the main timeline is a
    MovieClip instance.
    MovieClips play independently of one another, and can be
    nested. So if you
    just take your 1000 frame clip and place it on a frame (any
    frame will do)
    it will play - so long as the play head of the parent clip is
    on that frame.
    And you said you have a stop(); on the main timeline, so I
    assume it is. So,
    like kglad said, just put the clip on stage...
    Dave -
    Head Developer
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/

  • Playing any movie clip or youtube crashes computer, problem has only been happening for 6 months, what has been changed?

    running Windows XP 3 newish computer with lots of memory and hard drive space. Used to be fine, could play any clip or movie then suddenly about 6 months ago it started crashing when any movie clip played. I believe its an update in Firefox that caused the problem as it started happening after an UPDATE automatically loaded. Have been trying to resolve but noone I ask for help from responds including Mozilla.

    running Windows XP 3 newish computer with lots of memory and hard drive space. Used to be fine, could play any clip or movie then suddenly about 6 months ago it started crashing when any movie clip played. I believe its an update in Firefox that caused the problem as it started happening after an UPDATE automatically loaded. Have been trying to resolve but noone I ask for help from responds including Mozilla.

  • AS3 to make movie clip not play on default?

    I created a movie clip that I want to play when a button is
    clicked and
    stop when another button is clicked.
    I have a stop action on the first frame where the 2 buttons
    appear and
    the movie clips resides. When I test the movie, the movie
    clip plays by
    default.
    How do I set it up so the movie clip does not play until the
    user clicks
    the play button?
    The code I am using:
    myPlay_btn.addEventListener(MouseEvent.CLICK, playMc);
    myStop_btn.addEventListener(MouseEvent.CLICK, stopMc);
    function playMc(e:MouseEvent):void{
    my_mc.play();
    function stopMc(e:MouseEvent):void{
    my_mc.stop();
    Thanks!!!

    Not sure if I understand. Where specifically should this be
    added to the
    code:
    myPlay_btn.addEventListener(MouseEvent.CLICK, playMc);
    myStop_btn.addEventListener(MouseEvent.CLICK, stopMc);
    function playMc(e:MouseEvent):void{
    my_mc.play();
    function stopMc(e:MouseEvent):void{
    my_mc.stop();
    Thanks!

Maybe you are looking for

  • Problem logging in to admin account on Apex 3.1

    I have just upgraded to Apex 3.1 and I'm getting an error when logging on as admin. After I click log in I get: Line: 35 Char: 1 Error: Object expected Code: 0 Line 35 is : "<td colspan="1" rowspan="1" align="left"><input type="button" value="Login"

  • Step Container Element not getting updated

    Hi,       I have created a step container element for handling comments with the same ABAP dictinary structure & import export       parameter of a existing workflow conatiner element  & binded with the WF container & step conatiner & i have the save

  • How to use RSA10 in BI7

    Hi Experts, Can any one please tell me how to work with RSA10, i am testing actually. Thanks MARK

  • HTTP Website testing

    Hi, I am looking to test a website by following a flow and filling out a bunch of forms. Is there a tool out there which can help me do this ? I have looked at httpunit but seems like I have to program in everything. In my case, 1. the flow remains t

  • Is it possible to enhance HRPAD31?

    Hi~~ I want to enhance table HRPAD31 using structure PAD31. The result of Transaction DDCHECK is that HRPAD31 can be enhanced (Char.-Type). If an enhancement of HRPAD31 is possible, then How can I enhance that table? PAD31 has no CI_XXXXX Structure.