?
Solved

AS2.0 can't trace attribute

Posted on 2005-04-03
9
Medium Priority
?
179 Views
Last Modified: 2010-04-03
HELLO this is the inside of a class:  My question is, how come I can't trace target_mc from inside of the moveMe function (comes up as undefined) even though I can trace it anywhere else and its fine?      

// *** VARIABLES
      private var target_mc:MovieClip;
      private var moveAmount:Number;
      private var mask_mc:MovieClip;
      private var maskDepth:Number;
      private var imageSpacing:Number;
      private var maskWidth:Number;
      private var right_arrow:MovieClip;
      private var left_arrow:MovieClip;
      private var button_mc:MovieClip;
      private var maskHeight:Number;
      private var movePixels:Number;

      // *** CLASS PROPERTIES
      static var RIGHT_ARROW_DEPTH:Number = 1;
      static var LEFT_ARROW_DEPTH:Number = 2;
      static var BUTTON_DEPTH_ADD:Number = 1;
      static var MOVE_SPEED:Number = 25;
      
      // *** CONSTRUCTOR
      public function MoveStrip(target:MovieClip,
                              x:Number,
                              y:Number,
                              h:Number,
                              thumbWidth:Number,
                              moveSpaces:Number,
                              depth:Number,
                              borderWidth:Number) {
            // assign values
            maskDepth = depth;
            target_mc = target;
            imageSpacing = borderWidth;
            maskWidth = (thumbWidth+borderWidth)*moveSpaces + borderWidth;
            maskHeight = h;
            movePixels = thumbWidth * moveSpaces;
            // functions
            createStripMask(maskWidth, h);
            attachButtons(target_mc);
            
      
      }
      
      private function attachButtons(target:MovieClip):Void {
            var buttonDepth = maskDepth + BUTTON_DEPTH_ADD;
            button_mc = target._parent.createEmptyMovieClip("button_mc",buttonDepth);
            
            right_arrow = button_mc.attachMovie("right_arrow", "right_arrow" + RIGHT_ARROW_DEPTH, RIGHT_ARROW_DEPTH);
            left_arrow = button_mc.attachMovie("left_arrow", "left_arrow" + LEFT_ARROW_DEPTH, LEFT_ARROW_DEPTH);
            
            // align buttons
            right_arrow._x = maskWidth-right_arrow._width;
            right_arrow._y = maskHeight;
            left_arrow._y = maskHeight;
            
            // arrow assignments
            right_arrow.onPress = function() {
                  moveMe();
            }
            left_arrow.onPress = function() {
                  moveMe();
            }
            
            
      
       }

      // actual move function
      public function moveMe() {
            trace(target_mc)
      }
      


thanks in advance...
0
Comment
Question by:grzegorczyk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 27

Expert Comment

by:negatyve
ID: 13693614
Does this class extends MovieClip?
0
 

Author Comment

by:grzegorczyk
ID: 13694871
no it doesn't
0
 
LVL 27

Expert Comment

by:negatyve
ID: 13695441
If I use it this way:

this.createEmptyMovieClip("mc", 1);
var test = new MoveStrip(mc, 10, 10, 100, 100, 20, 1);
test.moveMe();

it traces _level0.mc, which is correct...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:grzegorczyk
ID: 13697239
right but target_mc is not created in this class, its passed into it when MoveStrip is created... I can trace it fine in the constructor...
0
 
LVL 27

Expert Comment

by:negatyve
ID: 13697260
So how do you creat an instance of this class and pass it that parameter?
0
 

Author Comment

by:grzegorczyk
ID: 13697286
     // create empty movie clip that will contain all other movie clips
      private function createStripHolder (x:Number,y:Number,h:Number,w:Number,bgColor:Number):Void {
            strip_mc = target_mc.createEmptyMovieClip("strip_mc" + rootDepth, rootDepth);
            strip_mc._x = x;
            strip_mc._y = y;
            // draw background
            strip_mc.moveTo(0,0);
            strip_mc.beginFill(bgColor);
            strip_mc.lineTo(w,0);
            strip_mc.lineTo(w,h);
            strip_mc.lineTo(0,h);
            strip_mc.lineTo(0,0);
            strip_mc.endFill();
            }
....


....
var moveStrip:MoveStrip = new MoveStrip(strip_mc, strip_mc._x, strip_mc._y, strip_mc._height,thumbWidth,4,moveStripDepth, stripBorder);
0
 
LVL 27

Expert Comment

by:negatyve
ID: 13697502
You are not giving me enough informations. Using these classe:

// ========================================
// MoveStrip Class
// ========================================
class MoveStrip
{
// *** VARIABLES
     private var target_mc:MovieClip;
     private var moveAmount:Number;
     private var mask_mc:MovieClip;
     private var maskDepth:Number;
     private var imageSpacing:Number;
     private var maskWidth:Number;
     private var right_arrow:MovieClip;
     private var left_arrow:MovieClip;
     private var button_mc:MovieClip;
     private var maskHeight:Number;
     private var movePixels:Number;

     // *** CLASS PROPERTIES
     static var RIGHT_ARROW_DEPTH:Number = 1;
     static var LEFT_ARROW_DEPTH:Number = 2;
     static var BUTTON_DEPTH_ADD:Number = 1;
     static var MOVE_SPEED:Number = 25;

     // *** CONSTRUCTOR
     public function MoveStrip(target:MovieClip,
                         x:Number,
                         y:Number,
                         h:Number,
                         thumbWidth:Number,
                         moveSpaces:Number,
                         depth:Number,
                         borderWidth:Number) {
          // assign values
          maskDepth = depth;
          target_mc = target;
          imageSpacing = borderWidth;
          maskWidth = (thumbWidth+borderWidth)*moveSpaces + borderWidth;
          maskHeight = h;
          movePixels = thumbWidth * moveSpaces;
          // functions
          createStripMask(maskWidth, h);
          attachButtons(target_mc);


     }

     private function attachButtons(target:MovieClip):Void {
          var buttonDepth = maskDepth + BUTTON_DEPTH_ADD;
          button_mc = target._parent.createEmptyMovieClip("button_mc",buttonDepth);

          right_arrow = button_mc.attachMovie("right_arrow", "right_arrow" + RIGHT_ARROW_DEPTH, RIGHT_ARROW_DEPTH);
          left_arrow = button_mc.attachMovie("left_arrow", "left_arrow" + LEFT_ARROW_DEPTH, LEFT_ARROW_DEPTH);

          // align buttons
          right_arrow._x = maskWidth-right_arrow._width;
          right_arrow._y = maskHeight;
          left_arrow._y = maskHeight;

          // arrow assignments
          right_arrow.onPress = function() {
               moveMe();
          }
          left_arrow.onPress = function() {
               moveMe();
          }



      }
      function createStripMask()
      {
      }
     // actual move function
     public function moveMe() {
          trace(target_mc)
     }
}
// ========================================


and

// ========================================
// AnotherClass Class
// ========================================
class AnotherClass
{
      // create empty movie clip that will contain all other movie clips
      var rootDepth:Number = 1;
      var strip_mc:MovieClip;
      var target_mc:MovieClip;
      
      function AnotherClass(tmc:MovieClip)
      {
            target_mc = tmc;
            createStripHolder(10, 10, 10, 10, 0xFF0000);
      }
      private function createStripHolder (x:Number,y:Number,h:Number,w:Number,bgColor:Number):Void
      {
            strip_mc = target_mc.createEmptyMovieClip("strip_mc" + rootDepth, rootDepth);
            strip_mc._x = x;
            strip_mc._y = y;
            // draw background
            strip_mc.moveTo(0,0);
            strip_mc.beginFill(bgColor);
            strip_mc.lineTo(w,0);
            strip_mc.lineTo(w,h);
            strip_mc.lineTo(0,h);
            strip_mc.lineTo(0,0);
            strip_mc.endFill();
      }
      public function returnMeStripMc()
      {
            return strip_mc;
      }
}
// ========================================

your code works fine:

// ========================================
// EXAMPLE
// ========================================
this.createEmptyMovieClip("willBeAnotherClassTargetMc", 1);
var anotherClassInstance:AnotherClass = new AnotherClass(willBeAnotherClassTargetMc);
var strip_mc:MovieClip = anotherClassInstance.returnMeStripMc();

var moveStrip:MoveStrip = new MoveStrip(strip_mc, strip_mc._x, strip_mc._y, strip_mc._height,thumbWidth,4,moveStripDepth, stripBorder);
moveStrip.moveMe(); // traces _level0.willBeAnotherClassTargetMc.strip_mc1
0
 

Author Comment

by:grzegorczyk
ID: 13697581
right ok, but I'm trying to activate that function via onPress:

// arrow assignments
            right_arrow.onPress = function() {
                  moveMe();
            }

in the MoveStrip class but it traces undefined...
0
 
LVL 27

Accepted Solution

by:
negatyve earned 1000 total points
ID: 13697805
ok, then try:

            right_arrow.target = this;
            right_arrow.onPress = function()
            {
                  this.target.moveMe();
            };
            left_arrow.target = this;
            left_arrow.onPress = function()
            {
                  this.target.moveMe();
            };
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question