• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 590
  • Last Modified:

AS2 class attachMovie

The name of my .fla file is round.fla. In round.fla, I have a movieClip called "collisionToolTip" and the identifier is also named the same. Export for ActionScript and Export in first Frame are both checked.

Originally, the code was a function in the main .fla. I am now updating to use an external class instead. Everything was working before, but the movieClip is not appearing now. I know the syntax needs to be tweaked, but I am not sure what is needed for the attachMovie code.
import flash.geom.Rectangle;
// for collision detection
import com.gskinner.sprites.CollisionDetection;
//
class com.wfc.CollisionHandling extends MovieClip {
  private var myTextCollisions:Number = 0;
	
  function CollisionHandling() {
  }
	
  public function checkCollision(mc1, mc2, alphaAmount) {
    var collisionRect:Rectangle = CollisionDetection.checkForCollision(mc1, mc2, alphaAmount);

    if (collisionRect) {
      myTextCollisions = myTextCollisions + 1;
      _root.attachMovie("collisionToolTip","collisionToolTip",100,{_x:(25), _y:(75)});
    } else {
      _root.removeMovieClip(collisionToolTip);
    }  
  }
}

Open in new window

0
msukow
Asked:
msukow
1 Solution
 
TanLiHaoCommented:
Hmm, your code looks correct. I'm thinking whether you did import the class, to test, add a trace inside the checkCollison function like this.

public function checkCollision(mc1, mc2, alphaAmount) {
    var collisionRect:Rectangle = CollisionDetection.checkForCollision(mc1, mc2, alphaAmount);

    if (collisionRect) {
      myTextCollisions = myTextCollisions + 1;
      var tempMovie:MovieClip =   _root.attachMovie("collisionToolTip","collisionToolTip",100,{_x:(25), _y:(75)}));
trace("succesfully called");
trace(tempMovie == undefined);
    } else {
      _root.removeMovieClip(collisionToolTip);
    }  
  }
This not just test whether you have imported the class, it also test whether the movie has successfully been attached. Tell me the output you get. If you get no output, then there is a problem with importing or you didn't call the function at all.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now