Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How can I reference the main timeline on a swf once it was loaded into another?

New Here ,
Jun 17, 2013 Jun 17, 2013

I have an swf with some custon animation functions using actionscript 3. I'm refering to the main timeline with Movieclip(root) and it works just fine.

However, this swf is going to be loaded inside another (a custom player), and when that happends, everything stops working.

I think it's because the Movieclip(root) is now referencing to the loader swf and not the loaded anymore, but I just can't find any information on how to fix that.

TOPICS
ActionScript
819
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jun 17, 2013 Jun 17, 2013

The key would be to break away from the use of root references.  Whether or not that will be an easy task for you in this case depends on just how saturated your code is with such references.  THe shortest route for you might be to replace root references with parent references instead.

This is one reason people say your coding should be limited to one frame in the main timeline (actually they are more likely to say it should be in a document class - separate from the fla file/timeline).  If you

...
Translate
LEGEND ,
Jun 17, 2013 Jun 17, 2013

The key would be to break away from the use of root references.  Whether or not that will be an easy task for you in this case depends on just how saturated your code is with such references.  THe shortest route for you might be to replace root references with parent references instead.

This is one reason people say your coding should be limited to one frame in the main timeline (actually they are more likely to say it should be in a document class - separate from the fla file/timeline).  If you have all the code looking forward into the file, and no code looking backward, which ios what a root reference is doing, then you don't have to worry about how it sits when loaded into another file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 17, 2013 Jun 17, 2013

I get it, I know I should stop using root, but I just can't find any other way of doint the same thing. And changing to parent doesn't help either.

I just wanted a way to make my code work inside this swf in a way that it could be loaded into anything without braking my code.

Most of my code is already on the frame 1. I'm just calling functions from the other frames to make my animations work when they have to.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 17, 2013 Jun 17, 2013

Using parent references should work.  But you have to know how many you need to reach the root.  Since you haven't shown/explained any code, that's the best I can offer.

If you showed the circumstances in which you use it, the more correct way to do it might be offered.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 17, 2013 Jun 17, 2013

This is basically what I´m doing here:

I'm placing this code on frame 1, and calling the function textAnimate() whenever I need to insert some text.

// This is a variable I created for tracking the timeline

var base:MovieClip = MovieClip(root);

function textAnimate(movieName:String, espera:Number):void {

 

          //var espera:Number = 1; //Waiting time

 

          var objeto:MovieClip = base[movieName]; //Variable to select the object

 

          var posFinal:Number = objeto.x; // Object position

          var posEnter:String = "-160"; // Animation start (relative)

          var posExit:String = "+160"; // Animation end (relative)

 

          // enter animation

          TweenMax.from(objeto, 1, {x:posEnter, alpha:0, blurFilter:{blurX:40}, ease:Back.easeOut});

 

          //call exitAnimation() after X seconds

          TweenMax.delayedCall(espera,exitAnimation);

 

          //exit animation

          function exitAnimation() {

                    TweenMax.to(objeto, 1, {x:posExit, alpha:0, blurFilter:{blurX:40}, ease:Back.easeIn});

          }

}

The swf works fine, but once it´s loaded into the player, nothing works anymore. Unfortunately, I don't have the code for the player, and can't change anything about it... 😕

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 17, 2013 Jun 17, 2013
LATEST

If that code is in the main timeline, you do not need to reference the root at all... You are in the root of the file if so.  In this case "this" would suffice in place of the one place you using "base".

I see you have a named function nested within the other.  That is something you also need to stop doing.  Never nest functions within functions.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines