1

I am trying to access vars, functions and objects hard coded on the main timeline from a class. The Objects, vars etc... are loaded when I call a function in the class like this:

Some code from main timeline:

import com.beauMoves;
var bm = new beauMoves();

bm.thisWorks();

and below is the class. But it is not accessing the main timeline. In this case I am trying to access a display object loaded from the lib and place on the timeline. The object is called "Beau" as you can see in the code below.

   package com {

import flash.display.MovieClip;
import com.*;   

public class beauMoves extends MovieClip 
{


        public function beauMoves()
        {
            // constructor code
            trace("BeauMoves");
        }

        public function thisWorks()
        {
            trace("Cool Beans! This one worked");
                    // THESE TWO LINES BELOW ARE NOT WORKING
            var main:MovieClip = MovieClip(this.parent);
            main.Beau.alpha = .3;

        }

}


}
Papa De Beau
  • 3,744
  • 18
  • 79
  • 137

1 Answers1

0

Presuming the two lines below are on the main timeline, pass to beauMoves() this as a constructor argument:

import com.beauMoves;
var bm = new beauMoves( this );

Then in your beauMoves() class:

package com {

    import flash.display.MovieClip;
    import com.*;   

    public class beauMoves extends MovieClip 
    {
        private var _mainTimeline:MovieClip;

        public function beauMoves( mainTimeLine:MovieClip )
        {
            // constructor code
            trace("BeauMoves");

            _mainTimeline = mainTimeLine;
        }

        public function thisWorks()
        {
            trace("Cool Beans! This one worked");

            _mainTimeline.bm.alpha = .3;

        }

    }

}

Matthew
  • 9,851
  • 4
  • 46
  • 77
Ribs
  • 1,449
  • 2
  • 13
  • 27
  • Thank you. However, I get this error:beauMoves.as, Line 22 1120: Access of undefined property mainTimeline. – Papa De Beau Sep 05 '13 at 19:47
  • if line 22 was this: _mainTimeline.bm.alpha = .3;, make sure it has the underscore in front of it. should be _mainTimeline not mainTimeline. – Ribs Sep 05 '13 at 22:23
  • yeah, I changed that. I copied and pasted your code and changed it up and then back again but no go. :( – Papa De Beau Sep 05 '13 at 22:25
  • You were right my friend but it was missing a case sensitive letter. I edited the code and gave you the correct answer. Thank you so much. – Papa De Beau Sep 09 '13 at 20:09