[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

hitTest for moving objects

Hello,

I have a number of movieclips on the scene, and one other movieclip which is animated by actionscript to move from left to right (something like a timeline). I want things to happen if the moving thing is on top of one of the other movieclips.

I know you can do that with hitTest if you use onmouse startDrag - stopDrag, but I have no mouse-events because it is moved by actionscript.

Any ideas how I can do this ?
Is it possible to use hitTest with addListener ?

Thanks,
Frank
0
Amigo_fd
Asked:
Amigo_fd
  • 6
  • 3
1 Solution
 
BillystyxCommented:
give the single mc an instance name - like myMC_mc
give the other mcs instance names like mc1, mc2, mc3 etc
click on that mc and in the action script editor for that clip, add
onClipEvent(enterFrame){
for (i=1;i<numofmcs;i++){
if(this.hitTest(_root["mc"+i])){
//do something;
}
}
}

Billystyx


0
 
BillystyxCommented:
(Obviously it depends on what you want to happen as to what goes in the line //do something)
Billystyx
0
 
Amigo_fdAuthor Commented:
thanx a lot ! works perfect ...

I have no more available points, so I can't start an other question, so maybe you also want to help me with on other question. I want to move the myMC_mc from left to right on a button click, with an adjustable speed.

I tried some components with which you can control the speed (Simple effects library > mover and Dykin Mover Components set), but they have an ease-out effect and I just want a linear move at the same speed from beginning to end. Any ideas ?
0
Technology Partners: 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!

 
BillystyxCommented:
on _root timeline put
dir=0;
//also add an input textfield(for starters), with var name 'speed'
//on the button put
on(release){

if(_root.dir==0 && this._x<550){
myMC_mc._x +=_root.speed;
}else if(_root.dir==0 && this._x>550){
_root.dir=1;
}
if(_root.dir==1 && this._x>0){
myMC_mc._x -=_root.speed;
}else if(_root.dir==1 && this._x<0){
_root.dir=0;
}
}

Billystyx
0
 
BillystyxCommented:
when it starts you type a speed into the input field and push the button

Billystyx
0
 
Amigo_fdAuthor Commented:
had to rewrite it a little but:

on (click) {
      trace("start " + _root.dir + "\t" + this._parent.myMover._x);
      _root.speed = 100;
      
      if (_root.dir == 0 && this._parent.myMover._x < 550) {
            this._parent.myMover._x += _root.speed;
      } else if(_root.dir == 0 && this._parent.myMover._x > 550){
            _root.dir = 1;
      }
      if (_root.dir == 1 && this._parent.myMover._x > 0) {
            this._parent.myMover._x -= _root.speed;
      } else if (_root.dir == 1 && this._parent.myMover._x < 0){
            _root.dir = 0;
      }
}

but this way myMover "jumps" to the new location _x + speed.

I should need something like so if you click once, myMover moves from left to right:

for (i=0;i<=550;i+=_root.speed) {
       this._parent.myMover._x = i;
}
0
 
BillystyxCommented:
Yes, true, this should also be on the enterframe of the mymc_mc

like this:
onClipEvent(enterFrame){
for (i=1;i<numofmcs;i++){
if(this.hitTest(_root["mc"+i])){
//do something;
}
}
if(_root.clicked=="1"){
if(_root.dir==0 && this._x<550){
myMC_mc._x +=_root.speed;
}else if(_root.dir==0 && this._x>550){
_root.dir=1;
}
if(_root.dir==1 && this._x>0){
myMC_mc._x -=_root.speed;
}else if(_root.dir==1 && this._x<0){
_root.dir=0;
}
}
}


and on the button
_root.clicked="1";

and on the _root, where the 'dir' is initialized:

clicked=0;

Billystyx
0
 
Amigo_fdAuthor Commented:
thanks a lot !!!
0
 
BillystyxCommented:
no worries - glad to help:)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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