Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Attatching Movie Clip (Dual Ball)



Hi,

When a ball hits a certain movie clip i want another ball to appear on the screen (dual ball action). I have tried the following code but when the second ball appears the users lives just disapear.


Code:
if (this.hitTest (ball)){
_root.DXScore +=2;
_root.Ball2.attachMovie("secondball");
instanceCounter--;
if(instanceCounter == 0){
gotoAndStop(1);}
this.removeMovieClip();
}
}
Can anyone offer me any ideas on how this problem could be solved

thanks in advance



ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 05-20-2007, 09:36 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Attatching Boxes To A Movie Clip
I have a table which expands and contracts, below i have boxes which can be dragged, i want it so that when the boxes are dragged onto the slots on the table they stick there and are non dragable.

so when the table is expanded and collapsed the boxes are still there in their slots.

i've attached the fla.

Attatching Boxes To A Movie Clip
I have a table which expands and contracts, below i have boxes which can be dragged, i want it so that when the boxes are dragged onto the slots on the table they stick there and are non dragable.

so when the table is expanded and collapsed the boxes are still there in their slots.

i've attached the fla.

Attatching A Movie Clip In Shoot Em Up Game
Hi.
I am trying to make a shoot em up game and I want to, when you shoot the bad guy, a movie clip will be played. eg. him dying
Plz tell me the actionscripts or whatever I need to know
PLEASE

Attatching A Movie Clip To Play 3 Times Through Then Destroy()?
How would i attatch a movie clip, call it to play three times through then remove it from the stage when a button is pressed? Would i have to use an interval or are there other methods?

Help Again Pls, Its About Attatching Movie
hi,
i have problem again . Last time i wanted to attatch text and photos in movie clip after pressing button in my menu. Someone gave good hint and I did part of my project, its working but not 100%.
There is one movie clip holder and 2 movie clips - one with text, second with pics. So far there are buttons that after pressing are showing what i want, but just 2 buttons and i have still few others. I was trying to add next frame in text movieclip but when i tell the button to show it after pressing i have some errors like its not unloading last text or everything start to be messy. I really want the things to work, and I want to learn how to do it in the most easy way. I attach the fla file. Its in polish but dont worry, the problem is just about the buttons, so u dont have to understand this language. Please help me asap and thank you very much.

Attatching Several Movie Clips From The Library
Hu

I'm having a problem with attaching several mc dimanycly.

here is my code


Code:
package {
import flash.*;

public var arrayMc:Array= ["backGround", "image1","image2","image3"];
public class attachBackGround extends Sprite {
public function attachMC() {
for (var a:int=0; a<arrayMc.length; a++) {
var _container:Sprite = new Sprite();
addChild(_container);
var v:arrayMc[a]= new arrayMc[a]();
_container.addChild(new v);
}
}
}
}


I always get an error, and I can't see to pass the name of the movie to be attached dinamycly.

Thanks

jm

Problems With Attatching Movie Clips.
I have created this little bit of coding for an idea I had,the only problem is is that it wont work.


//create object
keyListener = new Object();
//use onKeyDown function
keyListener.onKeyDown = function() {
//get the Ascii code
keypressed = Key.getAscii();

//if the letter press is 99 ("c")
if (keypressed == 99 or keypressed == 67)
this.attachMovie("movieclip");

};
//add listener to keys for this to work
Key.addListener(keyListener);

I want it so when a key on the keyboard(c in this example)is pressed it loads up a movie clip in place of the one on the page and plays it.I have tried many different things but still can not get it to work.

Does anyone have any ideas?

Cheers

Dual Slider Movie Manipulation
Hi,

I am using Flash MX to develop a movie that uses two sliders that interact with each other to manipulate the alpha value of two movies. I can easily code the values when a slider is at either end but its the in between values (when the sliders are both between _x 25 and _x 75) that I can't get right.

If anyone knows of a tutorial or can provide some insight I would appreciate it.

File and instructions are at:

http://www2.kumc.edu/netlearning/staff/jducey/temp.htm

Thanks!

Ball Vs. Ball Collisions: Un-penetrating The Ball
Hello

I have been reading tonypa's vector tutorials(http://www.tonypa.pri.ee/vectors/tut09.html), and I came across a special case that I am not sure how to deal with.

Suppose I have a ball bouncing around inside of a larger ball (I will call it the wheel). Now I know how to tell when the ball moves out of the wheel, and how I am supposed to move it back in (at least according to tonypa: var penetration=wheel.r-(ball.r+v.len) )
What I understand this does is it moves the ball back inside of the other ball along the line defined between the center of the ball and the center of the wheel.
However, wouldn't this be inaccurate? Shouldn't the ball be moved back along the line of the ball's original direction?

If so, how would I calculate the amount to move it back in?

Thanks in advance for your help.
Sorry if my post is confusing

Flash Movie Full Screen On Dual Monitors?
Hi potential helpfuls,
I would like to play a flash projector full screen across both my monitors for a project (I'm running an ATI radeon card that's powering one crt and one lcd monitor). the flash movie is set for the width of the whole desktop (1600 pixels, since my screen resolution for both monitors I'm setting at 800 X 600 pixels). But every time I launch the movie and kick it to full screen, the flash movie only plays on the primary monitor, essentially squeezing the whole thing on 1 monitor. Is there a way to solve this problem so the movie can launch full screen across both monitors?

Thanks,
Jean

Simple Pool Cue Hitting Ball - How To Get Direction For Ball To Head?
Hey guys. First post here.

I'm just learning how to program in ActionScript. What I'm trying to do is have a pool cue hit a ball, and based on the direction the pool cue is facing, the ball needs to go in that direction. I've got it set up using hitTest() so that if the mouse position (mouse position is the end to the cue) is touching the ball and "s" key is pressed, the ball is hit. But from here I don't know how to get the direction for the ball to go, or how to get it to start moving. Any guidance would be really appreciated. Thanks.

Ball Hitting Mouse Causes Ball To Go The Opposite Direction.
Here is my poor attempt to get into some scripting. I would like the ball to go the opposite direction if my mouse hits it.

I have a ball called ballmv.
I put this script on the ballmv:


Code:

onClipEvent(load){
speed = 10;
}
// this causes my ball to bounce off the walls
onClipEvent(enterFrame){
this._x = this._x + speed;
if(this._x >= _root.wallPos -53 || this._x <= _root.wallPos2 +53){
speed = -speed;
}
}
// this is for the mouse to deflect the ball
onClipEvent(enterFrame){
var xMouse = _root._xmouse;
if(xMouse.hitTest(_root.ballmv)){
with(_root.ballmv){
speed = -speed;
}
}
}



Also, am I writing my coding the long way? How should I write this. The mouse ball deflect thing doesn't work though but the others do.

Attatching .doc's
how do i create a button that downloads a text file onto the users desktop?

Attatching A.S. Dynamically?
Hey guys,

Is it possible to attatch a chunk of code to a movieclip that was created dynamically? Like for example sticking an "On enterframe" script to a MC created somewhere durring runtime. Or attatching an "On release" action to a dynamically created button...

Thanks, this would really help out

Attatching A Loadmovie
Hi,

How do I use the attatchmovie action in a button after I have loaded an external movie using the loadmovie action in the same button, eg.

I want to load an external movie into my main movie from a button, I know how to do that with the loadmovie action, but once I have it loaded how do I attatch the movie to a particular part of the movie like an attatchmovie action can do, thanks, looked around the forum for an answer to this cant find anything with both actions being used at once, I would of thought alot of sites would be using this method to cut down the preloading waiting time on the main movie.

eg. need loadmovie and attatchmovie in the same button.

Cheers.
Dean

Help With Attatching Fonts...
I have created a mailform with alot of input text boxes. I want to use a flash-font in all of them. Do I attach the font/characters to each of the boxes? Or is it a better way of doing this?

Setting A Variable: Var Ball Or Ball?
Hi,

I might be asking a stupid question so please excuse me.

What's the difference between the below and when should I use which?

Code:
ball=50;

and

Code:
var ball=50;


Thanks

Line From One Ball To Another Draggable Ball.
http://www.geocities.com/nmgwebsite/thing.swf
You will need to Copy and paste the url.
code:
onClipEvent (load) {
startDrag("_root.ball", true);
}
onClipEvent (enterFrame) {
x = _root.ball._x-_root.ball2._x;
y = _root.ball._y-_root.ball2._y;
radians = Math.atan2(y, x);
degrees = radians/(Math.PI/180);
_root.bar._rotation = degrees;
distance = Math.sqrt(x*x+y*y);
_root.bar._xscale = distance/1.78;
}


That just does not look right. Does anybody know what I am doing wrong? Thanks!

Ball Vs Ball Collision Revisited
Ok, before I get flamed, I know there are tons of posts dealing with ball vs ball collision and I have looked over any I could find on the forum, however none of them seem to work exactly like I want and I have been looking over examples for weeks now.
I have a script I modified from jbum's example (http://board.flashkit.com/board/show...hreadid=538918) that is pretty close but there is one problem I have yet to solve. Here is my modified code:

This part just updates the balls position based on their vx and vy variables. It gets called on a timer:
code:
public function moveBalls():void {
var loopLength=ballArray.length-1;
for (var count:int=0; count<=loopLength; count++) {
var currentBall=ballArray[count];
var currentBallRadius=currentBall.ballRadius;
currentBall.tempX = currentBall.x;
currentBall.tempY = currentBall.y;
currentBall.tempX += currentBall.vx;
currentBall.tempY += currentBall.vy;

if (currentBall.tempY-currentBallRadius<topEdge) {
currentBall.tempY = topEdge+currentBallRadius;
currentBall.vy *= -1;
}
else if (currentBall.tempY+currentBallRadius>bottomEdge) {
currentBall.tempY = bottomEdge-currentBallRadius;
currentBall.vy *= -1;
}
if (currentBall.tempX-currentBallRadius<leftEdge) {
currentBall.tempX = leftEdge+currentBallRadius;
currentBall.vx *= -1;
}
else if (currentBall.tempX+currentBallRadius>rightEdge) {
currentBall.tempX = rightEdge-currentBallRadius;
currentBall.vx *= -1;
}
}
for (count=0; count<=loopLength; count++) {
currentBall=ballArray[count];
for (var subCount:int=count+1; subCount<=loopLength; subCount++) {
var currentSubBall=ballArray[subCount];
var xdiff:Number = currentSubBall.tempX-currentBall.tempX;
var ydiff:Number = currentSubBall.tempY-currentBall.tempY;
var dist:Number = Math.sqrt(xdiff*xdiff+ydiff*ydiff);

if ((dist<=(currentBallRadius+currentSubBall.ballRadi us)) && (!currentBall.isCollide ||!currentSubBall.isCollide) ) {
currentBall.isCollide=true;
currentSubBall.isCollide=true;
doCollisionNew(currentBall,currentSubBall,dist,xdi ff,ydiff);
}
else {
currentBall.isCollide=false;
currentSubBall.isCollide=false;
}

}
}
updateBalls();
}


Next we actually update the balls real position:
code:
function updateBalls():void {
var loopLength=ballArray.length-1;
for (var count:int=0; count<=loopLength; count++) {
var currentBall=ballArray[count];
currentBall.x = currentBall.tempX;
currentBall.y = currentBall.tempY;
}
}


Ok, and here is the real part I'm having problems with. It gets called when there is a collision:
code:
function doCollisionNew(b1:BreakerBall, b2:BreakerBall,dist,xdiff,ydiff):void {
var mag1 = Math.sqrt(b1.vx*b1.vx+b1.vy*b1.vy);
var mag2 = Math.sqrt(b2.vx*b2.vx+b2.vy*b2.vy);
if ( dist==0) {
var angle = Math.atan2(ydiff,xdiff);
var cosa = Math.cos(angle);
var sina = Math.sin(angle);
var diff = ((b1.ballRadius+b2.ballRadius)-dist)/2;
var cosd = cosa*diff;
var sind = sina*diff;
b1.tempX -= cosd;
b1.tempY -= sind;
b2.tempX += cosd;
b2.tempY += sind;
b2.vx=-b1.vx;
b2.vy=-b1.vy;
b1.vx=-b2.vx;
b1.vy=-b2.vy;
}
else {
b2.vx = (mag1*xdiff/dist);
b1.vx = -(mag2*xdiff/dist);
b2.vy = (mag1*ydiff/dist);
b1.vy = -(mag2*ydiff/dist);
}
}

Most of it is the same as jbum's script except I added the part within the if statement ( if (dist==0) {....} ). This is kind of a hack, because I found if the balls are moving fast enough where they end up on top of each other, the vx/vy comes back as NaN and the balls end up stuck in the top left corner of the screen. Probably not the "right" way to do things, but it seems to work ok for my purposes.

Alright, so what I'm looking for is a random number of balls bouncing around the screen and colliding against each other in the simplest way possible. Everything works fine with this code, however if two balls start at the same Y position and travel down and toward each other, they collide wrong. Instead of moving outward from each other and continuing down, instead they just get stuck bouncing back and forth straight on x. Here is an example of this where ball1 starts at x=30, y=50 and ball2 starts at x=230, y=50. The first ball has vx=5, vy=5 and the second ball is vx=-5, vy=5.
http://metalblend.com/ballTest/proto-2a.html

This should work more like this:
http://metalblend.com/ballTest/proto-2b.html

The problem I see is that if the first balls vy is equal to the second balls vy then the variable ydiff is equal to zero. This causes this
code:
b2.vy = (mag1*ydiff/dist);
b1.vy = -(mag2*ydiff/dist);

to set both balls vy to zero, making them 'stuck' on the x plane.

I can get it to work right (shown in the second link) using this script for the collision calculation instead:
code:
function doCollision(b1:BreakerBall, b2:BreakerBall, dist:Number, xdiff:Number, ydiff:Number):void {
var angle = Math.atan2(ydiff,xdiff);
var cosa = Math.cos(angle);
var sina = Math.sin(angle);

var vx1p = cosa*b1.vx+sina*b1.vy;
var vy1p = cosa*b1.vy-sina*b1.vx;
var vx2p = cosa*b2.vx+sina*b2.vy;
var vy2p = cosa*b2.vy-sina*b2.vx;

var P = vx1p+vx2p;
var V = vx1p-vx2p;

vx1p = (P-V)/2;
vx2p = V+vx1p;

b1.vx = cosa*vx1p-sina*vy1p;
b1.vy = cosa*vy1p+sina*vx1p;
b2.vx = cosa*vx2p-sina*vy2p;
b2.vy = cosa*vy2p+sina*vx2p;

var diff = ((b1.ballRadius+b2.ballRadius)-dist)/2;

var cosd = cosa*diff;
var sind = sina*diff;

b1.tempX -= cosd;
b1.tempY -= sind;
b2.tempX += cosd;
b2.tempY += sind;

}


There are a couple problems with using the second script though. One of the main problems, is that I would like all the balls to stay at a constant speed after they collide. This is probably more of a "fake" collision, but that is what I am looking for. With this second function if you start all balls out with the same speed like vx=5,vy=5 for all balls, after bouncing for a bit, some start to move slower and some start to move faster.
Here is an example of this problem (using the more complex script):
http://metalblend.com/ballTest/proto-2c.html

The first script (jbum's) doesn't do this (they stay at a constant speed):
http://metalblend.com/ballTest/proto-2d.html
Also this second function has much more calculations to it and I'd rather keep it simple to avoid overhead and frame rate problems when dealing with a lot of balls bouncing. As well, this script is too confusing for me to understand for the most part .

So...if anyone knows an easy way to make the first script work right, without the problem of getting stuck on the x plane, MUCH APPRECIATED .

Oh,and the source file's I'm playing with can be downloaded here:
http://metalblend.com/ballTest/ballTest.zip

Ball Game (ball Goes Through Boundaries)
I have a ball game where the ball is suppesed to bounce off of the boundaries to get to the finish (the player draws a set of boundaries and then lets the ball fall and see if it makes it to the finish). It usually works but sometimes the ball goes through the boundaries. It is really bad when i have moving terrain because if the ball is going the opposite dirrection than the terrain it usually goes right through it. Also, I don't know if this can be fixed but sometimes the ball gets inside a line making up the terrain and starts bouncing around inside of the line. I have tried everything from increasing the frame rate to changing the variable values. please help.

heres the code for the ball ( sorry it's so long it repeats once so that the ball bounces off the players terrain as well as the premade terrain):

PHP Code:



onClipEvent (load) {
    yspeed = 0;
    xspeed = 0;
    gravity = 0.2;
    radius = 5;
    friction = 0.90;
    precision = 420;
    bounces = 0;
}
onClipEvent (enterFrame) {
    if (_root.go == true) {
        collisions = 0;
        sum_x = 0;
        sum_y = 0;
        yspeed = yspeed+gravity;
        for (x=1; x<precision; x++) {
            spot_x = _x+radius*Math.sin(x*360/precision);
            spot_y = _y-radius*Math.cos(x*360/precision);
            if (_root.terrain.hitTest(spot_x, spot_y, true)) {
                collisions++;
                sum_x += spot_x;
                sum_y += spot_y;
            }
        }
        if (collisions>0) {
            _root.last_hit._x = old_x;
            _root.last_hit._y = old_y;
            bounces++;
            _root.collisions.text = "Bounces: "+bounces;
            ball_dir = Math.atan(yspeed/(xspeed*-1))/(Math.PI/180);
            if ((xspeed*-1)<0) {
                ball_dir += 180;
            }
            if ((xspeed*-1)>=0 && yspeed<0) {
                ball_dir += 360;
            }
            spot_x = sum_x/collisions;
            spot_y = sum_y/collisions;
            x_cat = spot_x-_x;
            y_cat = spot_y-_y;
            ball_coll = Math.atan(y_cat/x_cat)/(Math.PI/180);
            if (x_cat<0) {
                ball_coll += 180;
            }
            if (x_cat>=0 && y_cat<0) {
                ball_coll += 360;
            }
            ground_rotation = ball_coll-90;
            if (ground_rotation<0) {
                ground_rotation += 180;
            }
            bounce_angle = 180-ball_dir-2*(ground_rotation);
            if (bounce_angle<0) {
                bounce_angle += 360;
            }
            speed = Math.sqrt((yspeed*yspeed)+(xspeed*xspeed));
            xspeed = speed*Math.cos(bounce_angle*Math.PI/180)*friction;
            yspeed = (speed*Math.sin(bounce_angle*Math.PI/180))*-1*friction;
            _x = old_x;
            _y = old_y;
        }
        else{
            old_x = _x;
            old_y = _y;
        }
        _y = _y+yspeed;
        _x = _x+xspeed;
    }
}
onClipEvent (enterFrame) {
    if (_root.go == true) {
        collisions = 0;
        sum_x = 0;
        sum_y = 0;
        yspeed = yspeed+gravity;
        for (x=1; x<precision; x++) {
            spot_x = _x+radius*Math.sin(x*360/precision);
            spot_y = _y-radius*Math.cos(x*360/precision);
            if (_root.terrain2.hitTest(spot_x, spot_y, true)) {
                collisions++;
                sum_x += spot_x;
                sum_y += spot_y;
            }
        }
        if (collisions>0) {
            _root.last_hit._x = old_x;
            _root.last_hit._y = old_y;
            bounces++;
            _root.collisions.text = "Bounces: "+bounces;
            ball_dir = Math.atan(yspeed/(xspeed*-1))/(Math.PI/180);
            if ((xspeed*-1)<0) {
                ball_dir += 180;
            }
            if ((xspeed*-1)>=0 && yspeed<0) {
                ball_dir += 360;
            }
            spot_x = sum_x/collisions;
            spot_y = sum_y/collisions;
            x_cat = spot_x-_x;
            y_cat = spot_y-_y;
            ball_coll = Math.atan(y_cat/x_cat)/(Math.PI/180);
            if (x_cat<0) {
                ball_coll += 180;
            }
            if (x_cat>=0 && y_cat<0) {
                ball_coll += 360;
            }
            ground_rotation = ball_coll-90;
            if (ground_rotation<0) {
                ground_rotation += 180;
            }
            bounce_angle = 180-ball_dir-2*(ground_rotation);
            if (bounce_angle<0) {
                bounce_angle += 360;
            }
            speed = Math.sqrt((yspeed*yspeed)+(xspeed*xspeed));
            xspeed = speed*Math.cos(bounce_angle*Math.PI/180)*friction;
            yspeed = (speed*Math.sin(bounce_angle*Math.PI/180))*-1*friction;
            _x = old_x;
            _y = old_y;
        }
        else{
            old_x = _x;
            old_y = _y;
        }
        _y = _y+yspeed;
        _x = _x+xspeed;
    }
}




terrain is what the player draws.
terrain1 is the premade background.

I can attach the file or add the code for drawing (but the drawing seems fine).

Ball Vs Ball Collision Revisited
I know there are tons of posts dealing with ball vs ball collision and I have looked over any I could find, however none of them seem to work exactly like I want and I have been looking over examples for weeks now.
I have a script I modified from this site
(http://www.krazydad.com/bestiary/bes...superball.html)
that is pretty close but there is one problem I have yet to solve. Here is my modified code:
This part just updates the balls position based on their vx and vy variables. It gets called on a timer:

ActionScript Code:
public function moveBalls():void { var loopLength=ballArray.length-1; for (var count:int=0; count<=loopLength; count++) {  var currentBall=ballArray[count];  var currentBallRadius=currentBall.ballRadius;  currentBall.tempX = currentBall.x;  currentBall.tempY = currentBall.y;  currentBall.tempX += currentBall.vx;  currentBall.tempY += currentBall.vy;  if (currentBall.tempY-currentBallRadius<topEdge) {   currentBall.tempY = topEdge+currentBallRadius;   currentBall.vy *= -1;  }  else if (currentBall.tempY+currentBallRadius>bottomEdge) {   currentBall.tempY = bottomEdge-currentBallRadius;   currentBall.vy *= -1;  }  if (currentBall.tempX-currentBallRadius<leftEdge) {   currentBall.tempX = leftEdge+currentBallRadius;   currentBall.vx *= -1;  }  else if (currentBall.tempX+currentBallRadius>rightEdge) {   currentBall.tempX = rightEdge-currentBallRadius;   currentBall.vx *= -1;  } } for (count=0; count<=loopLength; count++) {  currentBall=ballArray[count];  for (var subCount:int=count+1; subCount<=loopLength; subCount++) {   var currentSubBall=ballArray[subCount];   var xdiff:Number = currentSubBall.tempX-currentBall.tempX;   var ydiff:Number = currentSubBall.tempY-currentBall.tempY;   var dist:Number = Math.sqrt(xdiff*xdiff+ydiff*ydiff);   if ((dist<=(currentBallRadius+currentSubBall.ballRadius)) && (!currentBall.isCollide ||!currentSubBall.isCollide) ) {    currentBall.isCollide=true;    currentSubBall.isCollide=true;    doCollisionNew(currentBall,currentSubBall,dist,xdiff,ydiff);   }   else {    currentBall.isCollide=false;    currentSubBall.isCollide=false;   }  } } updateBalls();}

Next we actually update the balls real position:

ActionScript Code:
function updateBalls():void { var loopLength=ballArray.length-1; for (var count:int=0; count<=loopLength; count++) {  var currentBall=ballArray[count];  currentBall.x = currentBall.tempX;  currentBall.y = currentBall.tempY; }}

Ok, and here is the real part I'm having problems with. It gets called when there is a collision:

ActionScript Code:
function doCollisionNew(b1:BreakerBall, b2:BreakerBall,dist,xdiff,ydiff):void { var mag1 = Math.sqrt(b1.vx*b1.vx+b1.vy*b1.vy); var mag2 = Math.sqrt(b2.vx*b2.vx+b2.vy*b2.vy); if ( dist==0) {  var angle = Math.atan2(ydiff,xdiff);  var cosa = Math.cos(angle);  var sina = Math.sin(angle);  var diff = ((b1.ballRadius+b2.ballRadius)-dist)/2;  var cosd = cosa*diff;  var sind = sina*diff;  b1.tempX -= cosd;  b1.tempY -= sind;  b2.tempX += cosd;  b2.tempY += sind;  b2.vx=-b1.vx;  b2.vy=-b1.vy;  b1.vx=-b2.vx;  b1.vy=-b2.vy; } else {  b2.vx = (mag1*xdiff/dist);  b1.vx = -(mag2*xdiff/dist);  b2.vy = (mag1*ydiff/dist);  b1.vy = -(mag2*ydiff/dist); }}

Most of it is the same as jbum's script (http://www.krazydad.com/bestiary/bes...superball.html) except I added the part within the if statement ( if (dist==0) {....} ). This is kind of a hack, because I found if the balls are moving fast enough where they end up on top of each other, the vx/vy comes back as NaN and the balls end up stuck in the top left corner of the screen. Probably not the "right" way to do things, but it seems to work ok for my purposes.
Alright, so what I'm looking for is a random number of balls bouncing around the screen and colliding against each other in the simplest way possible. Everything works fine with this code, however if two balls start at the same Y position and travel down and toward each other, they collide wrong. Instead of moving outward from each other and continuing down, instead they just get stuck bouncing back and forth straight on x. Here is an example of this where ball1 starts at x=30, y=50 and ball2 starts at x=230, y=50. The first ball has vx=5, vy=5 and the second ball is vx=-5, vy=5.
http://metalblend.com/ballTest/proto-2a.html
This should work more like this:
http://metalblend.com/ballTest/proto-2b.html
The problem I see is that if the first balls vy is equal to the second balls vy then the variable ydiff is equal to zero. This causes this

ActionScript Code:
b2.vy = (mag1*ydiff/dist);b1.vy = -(mag2*ydiff/dist);

to set both balls vy to zero, making them 'stuck' on the x plane.
I can get it to work right (shown in the second link) using this script for the collision calculation instead:

ActionScript Code:
function doCollision(b1:BreakerBall, b2:BreakerBall, dist:Number, xdiff:Number, ydiff:Number):void { var angle = Math.atan2(ydiff,xdiff); var cosa = Math.cos(angle); var sina = Math.sin(angle); var vx1p = cosa*b1.vx+sina*b1.vy; var vy1p = cosa*b1.vy-sina*b1.vx; var vx2p = cosa*b2.vx+sina*b2.vy; var vy2p = cosa*b2.vy-sina*b2.vx; var P = vx1p+vx2p; var V = vx1p-vx2p; vx1p = (P-V)/2; vx2p = V+vx1p; b1.vx = cosa*vx1p-sina*vy1p; b1.vy = cosa*vy1p+sina*vx1p; b2.vx = cosa*vx2p-sina*vy2p; b2.vy = cosa*vy2p+sina*vx2p; var diff = ((b1.ballRadius+b2.ballRadius)-dist)/2; var cosd = cosa*diff; var sind = sina*diff; b1.tempX -= cosd; b1.tempY -= sind; b2.tempX += cosd; b2.tempY += sind;}

There are a couple problems with using the second script though. One of the main problems, is that I would like all the balls to stay at a constant speed after they collide. This is probably more of a "fake" collision, but that is what I am looking for. With this second function if you start all balls out with the same speed like vx=5,vy=5 for all balls, after bouncing for a bit, some start to move slower and some start to move faster.
Here is an example of this problem (using the more complex script):
http://metalblend.com/ballTest/proto-2c.html
The first script (jbum's) doesn't do this (they stay at a constant speed):
http://metalblend.com/ballTest/proto-2d.html
Also this second function has much more calculations to it and I'd rather keep it simple to avoid overhead and frame rate problems when dealing with a lot of balls bouncing. As well, this script is too confusing for me to understand for the most part .
So...if anyone knows an easy way to make the first script work right, without the problem of getting stuck on the x plane, MUCH APPRECIATED .
Oh,and the source file's I'm playing with can be downloaded here:
http://metalblend.com/ballTest/ballTest.zip

Attatching Mc's To Mc's Path Nightmare..
i have an empty movieclip on the stage.. called startTextMaster, it's instance is called startTextMaster and it's export for javascript name is also called startTextMaster.. so i attach a diff clip to it, called startButton (instance called startButton, export name also startButton) when i play my movie the startButton appears. I made a onRelease line which does what it's supposed to. _HOWEVER_ if i try to attatch another MC to it, say called 'startText' they both appear as expected but now, my onRelease doesn't happen when i hit the button. Anybody know the why of this weirdnesss?


Code:

startTextMaster.attachMovie("startButton", "startB",5);
//startTextMaster.attachMovie("startText", "startT",6);

_root.startTextMaster.startB.onRelease = function(){
trace("START TIMER");
// sooper = setInterval(doTimer, 1000);
}
sincere thanks,

dross

Attatching An Image To A Duplicated Mc
I am having trouble loading jpegs into duplicated mc's.

I can load it into a duplicated clip fine if i specify it ie:

loadMovie("photos/"+i+".jpg",thumbHolder3.imageHolder);

however, i am building these mc's in a for loop with:

duplicateMovieClip("thumbHolder",thumbHolder"+i,i) ;

I would like to load the images into these movie clips in this for loop as well, and am having trouble targeting the duplicated clips.

i am trying:
loadMovie("photos/"+i+".jpg",("thumbHolder"+i).imageHolder);

I even tried brackets instead of parenthesis, but I can't get it to work.

anyone know what i am doing wrong?

thanks

Attatching .avi To Button For Download
how do i attach a file to a button for download?

Attatching Code Dynamically
This is a simple bit of code that attaches a small movieClip onto the stage when the mouse moves.
What I am wanting to do as well is tell the newly dropped MovieClip to start rotating via action script. Is there a way I can do this via the frame that this current code resides?

code: _global.select = "drop_mc";
i = 1;
item = new Object();
item.onMouseMove = function() {
i++;
decalpos = {_x:_root._xmouse, _y:_root._ymouse};
_root.attachMovie(_global.select, _global.select, i, decalpos);
};
Mouse.addListener(item);

Attatching Code To Objects?
after you use attachMovie("clip", "clip", 1);, how can you attatch code to that object?

Attatching A Picture In A 3d Globe
hi can anyone help me with this globe?

heres my sample of the globe how do i make this?

or how do i attatch a picture into the globe ?



this picture will be the globe where by all the pictures will be clickable and then once clicked the video will pop up in the movie clip

and where my mouse goes to the left it will scroll left and to right it will then go to the right

i have this script where by it shows the whole globe thingy in flash mo but how do i make the pictures merged together like the picture ?

http://www.flashmo.com/preview/flashmo_097_3d_sphere

heres the link for the working file for the flash mo that i have downloaded.

could anyone please tell me how do i do to make them merge ?

if im not wrong the script there using is from papervision

regards
eugene

I Have A Ball In A Movie That I Would Like A Scrollbar To Control Using Mc Tween?
I have Ball-A that I can control its position in Flash using MC Tween x/y positions with a button. Thanks to Tann ; )

What I would like to know is, is it possible to build a scrollbar and control the ball with the scrollbar like I did with the button.

eg.
The scrollbar length in control will be equivalent to the Flash area where the ball is. Like the Flash area is 200px X 200px and the scrollbar is only 100px in length but if I move the scrollbar halfway, it will move the ball halfway. If I move it far left, it will move the ball far left. Like halfway of the scrollbar is 50px, but ha;fway of the Flash area is 100px so the ball moves there.

What script would I have to add to my scrollbar to control the ball?

Attatching A Script Onto A Dynamically Created Mc
how do i, having created a limited number of mc's then attatch an actionscript to those mc's that refer to only themselves...? You follow. Check the code below

This is the code i want to attatch to the mcs


Code:

onClipEvent (load) {
trgtx = this._x;
trgty = this._y;
}
on (press) {
this.startDrag();
_alpha = 40;
i=0;
}
on (release, releaseOutside) {
this.stopDrag();
_alpha = 100;
i=1;

}
onClipEvent(enterFrame){
if(i!=0){
floatTo(this, 2, trgtx, trgty);
}
}
see post below for a clearer explanation

Any ideas?



[Edited by buggedcom on 09-03-2002 at 07:48 PM]

Dynamically Attatching To A Motion Guide?
As the title says,

I'm wondering how i'd go about having a Symbol that's created at runtime, attatch to a specific end of a pre-made motion guide. And of course, how to then instruct it to move along the curve.

Thanks

Attatching AS To Movieclips Created Using DuplicateMovieClip
Hullo.

I'm trying to create a photogallery. I read both of the tutorials on the site, but couldn't find the answer to my problem. First, I will outline my methodology.

There is a directory called images, and therein are stored (surprise surprise) the images for the gallery. There is also a textfile that contains the number of images in the gallery.

Flash runs a loop that uses duplicateMovieClip to create instances of each image and set them up into rows and columns.

That's as far as I've gotten.

I want to be able to click these new movie clips, and have the image that was clicked appear in full size at the top of the screen. Basically, I just need to know how to assign actions to these newly created clips. Is it possible to do this when they are being created? Here's my code, thus far. I'm sorry if it's a backwards or stupid way of doing things, but I was trying to work from scratch, and my knowledge of actionscript is limited.


Code:
var beam:LoadVars = new LoadVars();

beam.load("/images/imagecount.txt");

row = 1;
col = 1;

beam.onLoad = function(){

count = beam.count;


for(i=1; i<6; i++) {
picpath = "/images/"+i+".jpg";
picholder = "pic"+i;
holder.duplicateMovieClip(picholder, i, {_x:(col*110), _y:(row*120)});
loadMovie(picpath, picholder);
col = col + 1;

if (col > 3) {
col = 1;
row = row + 1;
}
}
}

Attatching MC.onRelease Event Handler Via Loop
I'm trying to attatch an onRelease event handler at runtime to a bunch of MC's that are added via an xml doc. here's the totally lame why i've got it working at the mo:


ActionScript Code:
scrollclip.emptyMC.im1.onRelease = function() {
        imagePos = 0
    trace("this is the first")
        loadImage(imagePos);
    }
   
        scrollclip.emptyMC.im2.onRelease = function() {
        imagePos = 0.5
        loadImage(imagePos);
    }
        scrollclip.emptyMC.im3.onRelease = function() {
        imagePos = 1
        loadImage(imagePos);
    }


and here's what i'm trying to get to work...although i've tried a bunch of different conitations with no luck:


ActionScript Code:
ThumbsV = total_amount_of_MCs
   
    for(var q = 1; q < ThumbsV; q ++){
       
        scrollclip.emptyMC["im" + q].onRelease = function() {//these have already been added to the stage.
        imagePos = scrollclip.emptyMC["im" + (q-1)].imagePos + 0.5
        loadImage(imagePos);
    }
   
    }


if anyone can help or even shed light on this pain in the ass - it would be awesome!!

Making A Movie Clip In A Movie Clip Go To The Next Frame Of The Original Movie Clip
I have a movie clip (for simplicity I'll call it movie_a) in movie_a I have another movie clip movie_b.

in movie_a i have a button that when pressed makes movie_b play (it has a stop frame every once in a while so the button acts as a "next" button)

I want it so that when i get to the last frame of movie_b and press the button, it will go to the next frame of movie_a

I hope that doesn't confuse u and u can help me solve this problem, as i am stumped and I've tried everything I could think of (which isn't that much as I'm not too good with actionscript)

thnx

Ball VX And Ball VY Both Equal NAN
i have this script assigned to the ball, to bounce off of a circle, but when the ball hits the slime, somehow BallVX and BallVY are assigned the value of NAN, why is this happening?


ActionScript Code:
onClipEvent(load){
_global.ballVY = 0;
var maxXV = 15;
var maxYV = 22;
}
onClipEvent(enterFrame){
this._y += ++ballVY;
this._x += ballVX;
 dx = 2*((_root.ball._x)-(_root.slime._x));
 dy = (_root.ball._y)-(_root.slime._y);
 dist = Math.sqrt(dx*dx+dy*dy);
 dvx = ballVX - _global.P1XV;
 dvy = ballVY - _global.p1YV;
 if(dist < 52.5) {
    something = (dx*dvx+dy*dvy)/dist;
    _root.ball._x =  (_root.slime._x) +(92.5)/2*dx/dist;
    _root.ball._y = (_root.slime._y)+(92.5)*dy/dist;
        if(something <= 0) {
            ballVX += _global.P1XV-2*dx*something/dist;
            if(ballVX < -maxXV)
                ballVX = -maxXV;
            if(_global.ballVX > maxXV)
               ballVX = maxXV;
               ballVY += _global.p1YV-2*dy*something/dist;
            if(ballVY < -maxYV)
               ballVY = -maxYV;
            if(ballVY > maxYV)
               ballVY = maxYV;
         }
            fP1Touched = true;       
 }

}

Ball Bouncing Within Another Ball
Hi,

I am trying to create a script so that a ball will be able to:
1) Start within a larger circle and move in a random direction and a random speed, and
2) Bounce off the inside walls of the larger circle.

I want to make it so that the ball will be able to bounce off the tangent of the larger circle at the point where they hit (so the bounce will be accurate), but I don't know where to begin...

I can make the ball start within the circle and start moving in a random direction and a random speed, but I've looked everywhere for any scripting reference to bouncing off tangents to a circle and I have found nothing for actionscript.

All help is greatly appreciated! Thx in advance!

Targeting A Frame Label In A Movie Clip From A Button In A Separate Movie Clip.
I have two separate movie clips placed on a timeline-MovieclipA and MovieclipB. I have a button in MovieclipB clip that wants to target a frame label located in the MovieclipA timeline. Can someone help me?

Movie Clip Buttons Nested Inside Movie Clip Dont Work
Hi people!
im having a problem here.

in my first frame i have a movie clip named "menu_mc".
i have this AS for this movie:

Code:
this.menu_mc.onRollOver = function() {
menu_mc.gotoAndPlay(8);
}
this.menu_mc.onRollOut = function() {
menu_mc.gotoAndStop(7);
}

thats working ok, the menu_mc plays on rollover from frame 8 till frame 12 where stops.
On frame 12 (this is inside the menu_mc movie clip) i have another movie clip, named button1_mc.
and also i have AS controling that MC:

Code:
this.button1_mc.onRelease = function() {
getURL("index.htm", "_self");
}


The problem is that when i rollOver on menu_mc it work fine and the button1 appears, the problem is when i try to click button1...
doesnt work.

the swf you can see it on www.wt.com.mx/menu.swf
can anybody help me please?
what im doing wrong?
or what other ideas can you give me so i can make that work.

thanks!

Mouse Rollover On One Movie Clip Increase Decrease Alpha Of Another Movie Clip..
So I really haven't messed with Actionscript much for a couple years and here is my issue.

I have several movieclips I put together that will eventually be a menu for my website. When you roll over a menu option (movieclip) I am trying to get another movie clip to fade in giving the description of the menu item.

For example - when you roll your mouse over the 'Live Chat' option a brief text description would appear telling you what the live chat is about. This description is a seperate movie clip appearing away from the original menu.

I have made the movieclips for the menu and the movie clips for the descriptions. I tried this action on the menu option to get the description to fade in:


Code:
onClipEvent (load) {
this._parent.mc_text_discussionBoard._alpha = 0;
}
onClipEvent (enterFrame) {
this.onRollOver = function() {
if (this._parent.mc_text_discussionBoard._alpha<100) {
this._parent.mc_text_discussionBoard._alpha += 5;
}
};
}
But the alpha only increases on the description (mc_text_discussionBoard) by 5 when I keep rolling my move over and out and over again. It makes sense why it does that, but I'm not exaclty sure how to get it to continually increase the alpha by 5.

any help would be great and I am anxiously waiting to get this solved!
Kevin

Code 4 MovieClip Button To Load A Movie Clip Into A Placeholder Movie Clip.
Yeah that title sounds a little confusing...so i will explain:

Is there a way to tell a "movie clip button" that once it is clicked on to load a "movie clip" into a "movie clip placeholder". So instead of loading an external swf into the placeholder, it will be a movie clip from within the same library. Putting every single custom clip on the timeline would take a while, so that is why I thought it would be easier like this, and the other movie clips are not that large that I want to load into it so there is no need for external swfs, trying to keep it clean. Here is the code along the lines I am trying to go for.

__________________________________________

this.profile_mc.onRelease = function() {
placeholder_mc.loadMovie("profileSection_mc","plac eholder_mc","_root.content");
}
__________________________________________

- "profile_mc is the button I am trying to activate to load the
"profileSection_mc" into the "placeholder_mc". but so far no good.

- the movie clips are within the same library, not on the timeline or external library.

- Is this possible?

Using A Button In A Movie Clip To Control The Movie(and Not Movie Clip) Timeline
Ok i have a button placed in a movie clip. I want this button, when released, to go in another scene, frame one, on the movie(scene) timeline and not on the movie clip timeline.

So i tried: gotoAndPlay("mission", 1); (mission is the name of my scene)

But it goes to the frame 1 of my movie clip, It would be great if someone could tell me how i can control the movie timeline while my button is in a movie clip

thaks
Vakarm

A Movie Clip Inside A 2nd Movie Clip Colliding With 4th Movie Clip That's In The 3rd
sorry if that sounds a bit odd, this is really a simple problem that i can't seem to nail.

Can u please give the the hittest that shows when a movie clip collides with another regardless of their level.

How To 'stop' A Movie Clip Within A Movie Clip Within A Movie Clip Loop
I've done searches, laughed, cried, and punched holes through the wall, but I can't figure this out.

I'm in Flash MX (pro) and I have a MovieClip on my main timeline (frame 1). Inside that clip is another animation (the static animation scrolling across the screen), and another inside of it of the static animation (6 characters on a train each animated uniquely).

Confused yet? Ha! OK, so I just want the damned animation on the main timeline to run once and then stop (or to 270 frames). I've tried:

myMovieClip.stop()

to no avail. I've tried attaching the script to the movie clip itself, and also to the frame.

Any suggestions?

Making A Draggable Movie Clip Control The Location Of Another Movie Clip
http://www.kineticz.net/jba/residental.jpg that is a picture of what i am trying to do. the white bar at the bottom is the draggable movie clip and the group of 3 pictures right above that is the movie clip that i am trying to control w/ the draggable clip. I am having trouble writing a script that will do this. any help you can give will be much appreciated.

When I Click On A Movie Clip I Need The Movie Clip To Goto And Play Frame 2
i have created a movieclip and draged it on to the stage i tryed used on mouse down then tell target goto and play but that ment when ever the mouse clicked any where, how do i tell in to only play when i click on the movieclip ?

How Can I Control A Movie Clip Which Was Loaded In To A Empty Movie Clip On Level 0
how can i control a movie clip which was loaded in to a empty movie clip on level 0 the name of the movie is 'imagemc.swf' and 'imagemc' for the empty movie clip on level 0. the movie doesn't have a movieclip name, how am i going to tell target the movie?

How To Manipulate A Movie Clip On The Main Stage From Inside Another Movie Clip
I have a button inside a movie clip, and I want it to work that when you hit the button, a different movie clip will go to frame 5. anyone know how to help? I think it has something to do with which level it is on, but I can't manage to figure out anything else.

A Button Inside A Movie Clip, Within A Movie Clip, Calling Another Scene:
Is it even possible?

I have been trying to do it for the last few days for a site I am working on.

I have done searches in many forums and it's foolish looking for an answer that way, because quite frankly every thread I opened was something to do with LoadMovie or GetURL, etc.

What I have right now is on the button in my Menu Bar Movie Clip:

on (release) {
gotoAndPlay(285);
}

Which plays a fancy little animation in the movie clip and then on the last frame of that movie clip I had:

gotoAndPlay("Contact", 1);

Which is the Scene for the "Contact Us" Scene named "Contact"

One would think that it would load up the scene and play at frame 1, however all that happens is it reloads the movie clip of the "Menu Bar" at frame 1 and starts over, not even realizing what I asked.

Anyways, I figured there's a script or something that tells it to look outside of the movie clip or to the _Root, or whatever.

If someone has a solution, it would be greatly appreciated.

Sorry I have no example to show, since I have yet to upload it. (It's my company's web site, and I don't think customers would want to see some half-arsed web site that's not complete.

Thanks in advance.

On Mouseover Show Movie Clip, On Mouseout Close Movie Clip *HELP*
Basically what I am trying to do is this...

I have a movie clip that is a name. When you put your mouseover the name I want another movie clip to display to the right of the name. This clip has a photo and bio of the person.

The photo and bio have an animation that fades it in and an animation to fade it out. I have 5 frames for the fade in, then stop frame, then 5 frames for the fade out.

What actionscript do I need to use to make that second movie clip load when a user mousesover the name (first movie clip) and to make the second half of the second movie clip play when the user removes their mouse from name (first movie clip).

NOTE: I tried using loadMovie and unLoad movie but I couldn't do it loading another swf. The reason being this is already an swf loaded inside a main movie. I guess you can't load an swf inside an swf that's already loaded inside an swf. I hope this all makes sense!

I appreicate all the help!

Thanks a lot!

Create A Movie Clip As A Button To Jump To Half Way Through Another Movie Clip?
hi guys and gals,
i am wondering if i can make a movie clip (as a link for a website) jump to half way through another movieclip...
thanks in advance

Copyright © 2005-08 www.BigResource.com, All rights reserved