Reffering to code in the root timeline

I'm very suprised I theres not an obvious answer to this
question to be found. In AS 2 I would often write most of my code
in the main timeline, and then refer to it from various other
movies etc. I dont seem to be able to do that in AS 3? how can I do
it in AS 3?
For example if i had a function on the main timeline, and
wanted to call it from the code in another movie. In that past I
would have just used _root.functionName();

_root in AS3 is now simply root (no underscore). The root
property,
however, is only available to DisplayObject instances, not
other classes.
The root reference is also null unless the DisplayObject
instance is a child
of a display list attached to the stage. For timeline scripts
within a Flash
FLA, however, where the movie clip is added to the screen
within the Flash
environment, root is always available.
A good practice for globally accessible functions, however,
would be to
define your functions as static methods in a class. Then you
can reference
those functions anywhere from any object (even non
DisplayObject instances)
using ClassName.functionName()
"smazr123" <[email protected]> wrote in
message
news:f29rrb$4nl$[email protected]..
> I'm very suprised I theres not an obvious answer to this
question to be
> found.
> In AS 2 I would often write most of my code in the main
timeline, and then
> refer to it from various other movies etc. I dont seem
to be able to do
> that in
> AS 3? how can I do it in AS 3?
>
> For example if i had a function on the main timeline,
and wanted to call
> it
> from the code in another movie. In that past I would
have just used
> _root.functionName();
>

Similar Messages

  • Remove child on the root timeline from within a movieclip

    Hi
    How do I remove a child from the root timeline from within a separate movieclip?
    I've tried
    MovieClip(parent).removeChild(mc1);
    But I get this error
    1120: Access of undefined property mc1.
    I could write a function in the root timeline that just removes child and then run that from within the movieclip but is there a better way?
    Thanks in advance.

    Thanks for replying.
    I asked on Kirupa but I couldn't access the site so I asked here.
    I guy answered with this
    MovieClip(parent).removeChild(MovieClip(parent).getChildByName("mc1"));
    It works fine, is this the best way to do it?
    Not sure if I understand what you meant?
    Just to be clear I have to movie clips on the stage mc1 and mc2 and i want to remove mc1 from within mc2's timeline.
    Thanks again

  • Controll the ROOT timeline from externally loaded movie clip?

    does anyone know how to controll the root timeline from an
    externally loaded movie clip?
    I have loaded a movie clip, which has buttons on it that I
    would like to controll the main original website timeline with.
    something like this.parent.parent?
    thanks a lot
    harky

    feedmeapples <[email protected]> wrote:
    > does anyone know how to controll the root timeline from
    an externally
    > loaded movie clip?
    >
    > I have loaded a movie clip, which has buttons on it that
    I would like
    > to controll the main original website timeline with.
    >
    > something like this.parent.parent?
    _root.doStuff;
    Freundliche Grüße,
    Franz Marksteiner

  • Controlling the root timeline from inside a MovieClip

    [preface] I'll apologize in advance. I'm a designer, not a
    developer. I know very little about actionscript so if you
    can help me out, please pretend like I know nothing.
    [/ preface]
    I just need actionscript to check the value of a variable
    when the end of a movie clip is reached and then call an action.
    Here's what I've got and it doesn't work. Please don't laugh.
    if (p == 1){
    tellTarget (_root) {
    play();
    else if (p == 0){
    stop();
    (the "stop" on the "else if"
    is referring to the movie clip's timeline, not the root
    timeline... in case you're wondering)
    Any help would be greatly appreciated. Thanks!

    No it's not a school project. Good guess though. It's
    actually a self-promo piece for the ad agency I work for. I'm an
    art director expanding my horizons. I would take a class or run
    through one of the good actionscript books but unfortunately, I
    don't have time.
    Thanks for the help again kglad.
    btw, I've used tellTarget successfully in a few projects in
    the last few months. I'm using Flash 8.

  • Refering to a class imported on the root timeline?

    This is probably ueber basic, but I don't know how to do it.
    I am importing tweenlite on the root timeline like this:
    import gs.TweenLite;
    I now want animate things in other MCs. I tried something like this, but it did not seem to work.
    _parent.TweenLite.to(text1, 3, {_alpha:100, overwrite:0});
    How would I do this?
    Thanks a lot for any help with this!!!

    it's easiest to not even bother with the import statement and always use:
    gs.TweenLite.to();
    or
    gs.TweenLite.from()
    from any timeline.

  • 4 mc's on the root timeline. Using onClipEvents... all mcs play at once.

    I have 4 mc's on a root timeline. I'd like each, when clicked, to animate individually. Currently with the code I have, when I click one, they all play. 3 of these mc's are identical mc's (they have instance names, but aren't called out in the code, not sure how to). The fourth mc is a different mc altogether, yet this particular mc along with the other 3 (identical) all play at once.
    I thought using "this" would only have the mc I click on play. Not the case. I also tried putting the instance name (i.e. onoff1) bofore "this." and after "this." and no luck.
    Thanks for any help, and I regret to say that I'm not savvy in AS2, so I hope you don't mind spelling things out for me because this a bit over my head.
    Also, wanted to say, that the mc's timeline do have a stop at the beginning and end. So when you export the swf (currently) the mc is stopped, and when you click on it they all play to the next stop. So they act like I want them, just that they're all animating at once no matter which one I click.
    onClipEvent(mouseUp) {
    this.gotoAndPlay(1);

    Wow! You are the man!!!!! Karma points! Thanks so much.
    I've only used on(release) for buttons, and have always used onClipEvent(mouseUp) for mcs. I didn't know you could use on(release) for mcs, didn't think you could.
    I know enough AS3, more than AS2. I got a gig that asks for AS2 and I had to learn it from the ground up. I miss using the function command in AS3, I think I used it for everything.
    Thanks again.

  • Array to control MCs on the root timeline

    HI - - - a continuing saga
    I have a main timeline thats about 900 frames long. During
    the course of this 900 frames I bring in short MCs (subA, subB,
    subC, etc) on their own layer which play their duration - (a 90
    frame sub MC gets 90 frames on the main timeline).
    Using a mc I made into a play/pause btn, I can pause and
    resume play of the main timeline by targeting “_root”.
    I can also use the same button to pause/play the sub_mcs IF I
    list each one at the pause and play commands. I thought an array
    would help me avoid that code repetition but it doesn't work.
    Can someone look at my code and let me know what's missing
    and/or what I did wrong?
    TIA
    JL

    Hi --
    Try this:
    obj = allSubMCs[0]
    obj.play();
    etc..
    You have to define the index of the array. If you want the
    pause/play button
    to work for all MCs in the array then just loop through the
    array.
    Rich
    "jlucchesi" <[email protected]> wrote in
    message
    news:ghun7u$pjn$[email protected]..
    > HI - - - a continuing saga
    >
    > I have a main timeline thats about 900 frames long.
    During the course of
    > this
    > 900 frames I bring in short MCs (subA, subB, subC, etc)
    on their own layer
    > which play their duration - (a 90 frame sub MC gets 90
    frames on the main
    > timeline).
    >
    > Using a mc I made into a play/pause btn, I can pause and
    resume play of
    > the
    > main timeline by targeting ?_root?.
    > I can also use the same button to pause/play the sub_mcs
    IF I list each
    > one at
    > the pause and play commands. I thought an array would
    help me avoid that
    > code
    > repetition but it doesn't work.
    >
    > Can someone look at my code and let me know what's
    missing and/or what I
    > did
    > wrong?
    >
    > TIA
    >
    > JL
    >
    > var allSubMCs:Array = new Array("sub1_mc", "sub2_mc",
    "sub3_mc");
    >
    >
    > playPause_btn.onRollOver = function() {
    >
    > if(this._currentframe == 1) {
    > this.gotoAndStop("pauseOver");
    > }
    >
    > else {
    > this.gotoAndStop("playOver");
    > }
    >
    > }
    >
    >
    > playPause_btn.onRollOut = function() {
    >
    > if(this._currentframe == 10) {
    > this.gotoAndStop("pause");
    > }
    >
    > else {
    > this.gotoAndStop("play");
    > }
    >
    > }
    >
    >
    > playPause_btn.onRelease = function() {
    >
    > if(this._currentframe == 10) {
    > this.gotoAndStop("playOver");
    > _root.sub1_mc.stop(); // naming each sub mc does
    > //_root.allSubMCs.stop(); // the array doesn't work
    > _root.stop();
    > }
    >
    > else {
    > this.gotoAndStop("pauseOver");
    > //_root.allSubMCs.play(); // the array doesn't work
    > _root.sub1_mc.play(); // naming each sub mc does
    > _root.play();
    > }
    >
    > }
    > //------END PlayPause TOGGLE--------
    >

  • Reffering to Code in root timeline

    I'm very suprised I theres not an obvious answer to this
    question to be found. In AS 2 I would often write most of my code
    in the main timeline, and then refer to it from various other
    movies etc. I dont seem to be able to do that in AS 3? how can I do
    it in AS 3?
    For example if i had a function on the main timeline, and
    wanted to call it from the code in another movie. In that past I
    would have just used _root.functionName();
    RESPONCE:
    _root in AS3 is now simply root (no underscore). The root
    property,
    however, is only available to DisplayObject instances, not
    other classes.
    The root reference is also null unless the DisplayObject
    instance is a child
    of a display list attached to the stage. For timeline scripts
    within a Flash
    FLA, however, where the movie clip is added to the screen
    within the Flash
    environment, root is always available.
    A good practice for globally accessible functions, however,
    would be to
    define your functions as static methods in a class. Then you
    can reference
    those functions anywhere from any object (even non
    DisplayObject instances)
    using ClassName.functionName()
    RESPONCE:
    Ummm... I named my document class main, thinking that might
    help me refer to it from child clips, but it didnt. Using root
    seems to refer to main, but then I cant refer to anything on the
    stage, or any function written there. From reading the help I got
    the impression that function defined in the root timeline would
    become publicly accessable functions that could be accessed with
    dot notation. Is this not the case?
    When I trace root, or main, it outputs [object main]. So then
    thats the class... Why cant I refer to the functions of that class
    from another movie?
    Are you suggesting I write a document class with my functions
    in it? could I still refer to objects on the stage if I do that.
    I've read over these subjects alot in the documentation and its
    really not clear... perhaps someone could write a tutorial.

    _root in AS3 is now simply root (no underscore). The root
    property,
    however, is only available to DisplayObject instances, not
    other classes.
    The root reference is also null unless the DisplayObject
    instance is a child
    of a display list attached to the stage. For timeline scripts
    within a Flash
    FLA, however, where the movie clip is added to the screen
    within the Flash
    environment, root is always available.
    A good practice for globally accessible functions, however,
    would be to
    define your functions as static methods in a class. Then you
    can reference
    those functions anywhere from any object (even non
    DisplayObject instances)
    using ClassName.functionName()
    "smazr123" <[email protected]> wrote in
    message
    news:f29rrb$4nl$[email protected]..
    > I'm very suprised I theres not an obvious answer to this
    question to be
    > found.
    > In AS 2 I would often write most of my code in the main
    timeline, and then
    > refer to it from various other movies etc. I dont seem
    to be able to do
    > that in
    > AS 3? how can I do it in AS 3?
    >
    > For example if i had a function on the main timeline,
    and wanted to call
    > it
    > from the code in another movie. In that past I would
    have just used
    > _root.functionName();
    >

  • GotoAndStop at the the root of the timeline

    HI
    I have a movie clip with onRollOver and onRollOut script
    attached. When clicked I would like the root of the timeline to
    move to a different label. At present I have tried the following
    first script on the MC to move the root timeline, however this is
    not working and I assume this is due to the complexity of the movie
    clip:
    I have therefore used the following 2nd script for the first
    frame of the timeline within the MC which works with getURL but I
    am unable to get it to work with moving the root of the timeline.
    Do I need to add .root somewhere? Thanks

    Here is the answer:

  • Why does debugger not find source code when compiler output has been directed to the root directory, but the source is in a sub-directory, using Forte for JAVA community edition V3.0

    I have configured Forte to put compiler output, i.e. my classes, in the root directory of the project. I now find that the debugger does not find the source code when it is in a sub-directory. However, if I temporarily copy a classes' source code to the root directory the debugger will display it.
    To direct compiler output to the root directory I selected Project >Settings>Compiler types, then External Compiler ( which is the default compiler in my case ) and set Target to be the root project directory. This is the only directory it will allow.

    This Forum is for Forte 4GL or UDS as its called today. I am not sure if anybody is going to be able to answer your question here. Sorry.
    ka

  • Accessing Root Timeline Button

    Hi,
    I think this is a fairly basic thing to do, but I can't seem
    to figure it out. I have a movie clip(
    mc1) with a button(
    btn1) and a movie clip(
    mc2) in it. The button plays this second embedded movie
    clip(
    mc2). In this second movie clip(
    mc2), I have a button(
    btn2) that, when clicked, I would like to cause the first
    button(
    btn1) (on the root timeline) to disappear. Is this possible,
    and if so, could you help me figure out how to do so?
    Thank you,
    Brad
    EDIT: Just so its easier to visualize, here's a hierarchy of
    the relevant elements:
    mc1
    btn1
    mc2
    btn2

    Thank you kglad.
    Unfortunately, I'm not 100% sure what you're suggesting. Are
    you saying I should test to see if the btn2 will respond to a click
    using hitTest? If so, I already know that I can click on btn2
    because I have some actionscript that runs when I click it, and
    that particular part of the code is functional. However, I'm not
    sure what actionscript will allow me to modify btn1 when I click on
    btn2. One snippet of code that I tried (but didn't work) was:
    btn2.onRelease = function(){
    _root.btn1._alpha = 0;
    I'm guessing I'm doing something either wrong, or not
    possible, but I'm still pretty new to actionscripting, so I
    couldn't tell you. Anyway, thank you again, and I look forward to
    your response.
    -Brad

  • Load swf AFTER playing to end of root timeline

    Don't know if this can be done or not...
    I have my Home page - 5 Navigation buttons on the page. Each
    button "onRelease" will load an external swf file ( a new page).
    The problem i'm having is getting the the buttons to play the rest
    of the root timeline (after "Stop) before it loads the external
    swf. The rest of the timeline is just a short fade to Alpha 0 of
    all buttons before the new page comes in.
    any help?
    thanks in advance.

    michaeltowse wrote:
    > Could you not assign a variable which is then picked up
    at the end of the main
    > timeline. This variable could be used within a loadMovie
    command. Your buttons
    > would have the variable declaration and then a play()
    command.
    >
    What you seem to need is some sort of non unloading loading
    of the movie.
    You got the level loading method, the movieclip loading
    method and the
    dedicated loader class.

  • Using cue points to trigger events on the main timeline...

    Hi--
    I have successfully placed an flv (video) file (progressive
    download) on the main timeline of my movie with controls to play
    and pause (Flash 8 Professional). So far, so good!
    NOW TWO PROBLEMS: Does anyone know how to set it up so that
    when a specific cue point is reached in the video, it triggers an
    action on the main timeline? In this case, once the video is over,
    I want the main timeline to gotoAndPlay frame 3. Specific script to
    do this would be great!
    The other action I'd like to happen is that when the video
    begins, it targets a scrolling text mc ("text") in the main
    timeline and tells it to gotoAndPlay frame 2.
    Any advice would be GREATLY appreciated!!! Many
    thanks!!!

    I usually start off solving problems with the livedocs, as I
    recommend for anyone. The following link will take you to the
    NetStream.onCuePoint handler. This is what you need.
    http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context= LiveDocs_Parts&file=00002561.html
    You can have this code on the main timeline. When the
    cuepoint is hit, it will invoke this event handler and inside is
    where your gotoAndPlay( ) should go.
    Your other question about the text will get activated by the
    same handler. Just have a conditional statement (if, switch, etc.)
    to differentiate between the two events. The text itself can be
    mask inside a movieclip.
    Does this help?

  • Use timeline of a nested mc to affect the main timeline

    Hi I have a magic cloud effect. On frame 30 of the nested effect I would like an mc on the main timeline to become visible.
    Not too sure how to code with frame numbers,
    a) Do I put AS on the timeline of the nested clip OR
    b) Write code on the main timeline to listen for when the nested mc gets to frame 30
    Cheers

    Hi
    I got to the bottom of it.
    As you say really bad practise to bury code - had enough of that in AS2 and template monster.
    Realised that you could do all this from the main time line and therefore have everything visible.
    import flash.events.*;
    hero.visible = false;
    cloud.addEventListener(Event.ENTER_FRAME, handler);
    function handler (e:Event) {
    if (cloud.currentFrame == 21) {
    hero.visible = true;
    THANKS

  • FLV/Mp3 Cue Points for Accessing Frame Labels on the Main Timeline in Flash 8

    Hello,
    In Flash MX2004, creating cue points for syncing locations on
    flv and mp3 files to locations on the main timeline included:
    1) Dragging a media component onto the stage
    2) Entering file path, frame label name, and time code
    information in the component inspector
    3) Creating the frame label names on the main timeline, and
    4) Enabling the Media Labeled Frame Cue Point Navigation
    Behavior
    Flash 8 documentation details a considerably different
    process of creating cue points. While it discusses how to create
    cue points in the flv, I have not been able to locate how to enable
    linking locations in flv and mp3 files with frame labels on the man
    timeline. It appears that there would need to be ActionScript
    necessary to accomplish this that is not available in the docs.
    Please advise what ActionScript/process would enable this
    function.
    Thank you!
    James
    [email protected]

    I usually start off solving problems with the livedocs, as I
    recommend for anyone. The following link will take you to the
    NetStream.onCuePoint handler. This is what you need.
    http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context= LiveDocs_Parts&file=00002561.html
    You can have this code on the main timeline. When the
    cuepoint is hit, it will invoke this event handler and inside is
    where your gotoAndPlay( ) should go.
    Your other question about the text will get activated by the
    same handler. Just have a conditional statement (if, switch, etc.)
    to differentiate between the two events. The text itself can be
    mask inside a movieclip.
    Does this help?

Maybe you are looking for