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




Collision Detection Between Attached Movie Clips



Hello there!
I'm new to this forum but I've been playing around with Flash since I was little.

Recently I made a simple first-step to a game where you can point the character with the mouse and shoot with a click.
I'm adding characters to the world with the attachMovie() method, which is also the way I'm adding the bullets or magic bolts or whatever it's going to be.
This is the unfinished code for creating an enemy. Sorry for the Swedish. I'm in a hurry.


Code:
getEnemy = function() {
++djup;
var name = "snubbe"+djup;
_root.attachMovie("snubbe", name, djup);
_root[name]._x = 550;
_root[name]._y = random(400);
_root[name].onEnterFrame = function() {
//I think it's here the code will fit in...
}
};
};
and the following is the code for the bullets(no rotation).


Code:
depth=0;
_root.onMouseDown = function() {
angle = gun._rotation;
angle = angle*Math.PI/180;
++depth;
name = "skott"+depth;
_root.attachMovie("skott", name, depth);
_root[name]._x = gun._x*Math.cos(angle);
_root[name]._y = gun._y*Math.sin(angle);
_root[name].xåk = speed*Math.cos(angle);
_root[name].yåk = speed*Math.sin(angle);
_root[name].onEnterFrame = function() {
this._x += this.xåk;
this._y += this.yåk;
};
};
Thank you for your help.



ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 08-25-2006, 06:29 PM


View Complete Forum Thread with Replies

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

Collision Detection For Attached Movie Clips
Hello,

I have a difficulty that I need help overcoming. To give some background information, here are the movie clips used:

1 movie clip called 'skater'
1 movie clip called 'token'
In the actionscript, 'token' is incremented to become 'token1', 'token2', etc.

I am using attachMovie to place the new 'token(i)' at different points on the stage. I then want my 'skater' to be able to collect them using a hitTest. I know my code works for other things as I tried it by creating another movie clip called 'obstacle' and substituting it in place of 'token(i)' and it worked perfectly.

I don't understand why my code isn't detecting the attached movie clips.

If anyone can point me in the right direction, I would really appreciate it. I have attached my code for you to look at.

Looking forward to an answer soon.

Cheers
Psylova







Attach Code

var i = 0;
function tokens()
{
timeSinceLastToken ++;
trace(timeSinceLastToken);
if((timeSinceLastToken > 20) && (Math.random()<.1))
{
i++;
var newname = "token"+i;
_root.attachMovie("token", newname, i*100);
_root[newname]._y = Math.random()*490 +240;
_root[newname]._x = 520;
trace(newname);
trace(timeSinceLastToken);
}
}

// works up until here - I can't get the tokens to register that they've been hit.
// I know the code works as I've tried it out with another object 'obstacle'
function collectToken()
{
if (_root.skater, hitTest(_root[newname]))
{
//_root[newname].swapDepths(10000);
_root[newname].removeMovieClip();
trace("Token Hit!!");
score ++;
}
}

Collision Detection Between 2 Movie Clips
Hi, I was wondering if anyone could tell me how to detect if 2 movie clips are touching, even better, if one movie clip goes over a certain coordinate on another movie clip.

any help would be great
thanks, josh

[F8] Collision Detection With Non Square Movie Clips
Hey im trying to make a game engine where you can angle up slopes. To do this im trying to do a do collision detection on two points of my object to see if i can rotate the object according to the slope of the ground. But one thing is really screwing me up. My ground is a simple black line with another line running out of it for a jump (as will be shown if i can include the fla). Right now i have it so i can go up the slope, but without rotating to fit the angle. Since the ground has a line coming up from it it makes the movie clip hitTest area into a big square. Is there any way of making the movie clip's hitTest area not in a square but tight to the drawing?

[MX] Collision Detection Between Objects In Nested Movie Clips
I'm normally not one to bother people when I can't figure something out in Flash, but I'm stumped, so I'd appreciate anyone helping me out. In short, I am trying to have circles grow and shrink whenever an object that is orbiting the mouse passes over them. I'll try to fill in as many details about the flash movie as possible here...

The cursor is comprised of two layers of nested movie clips. The bottom-most movie clip is a 15x15 instance of a circle labeled electron, offset from the center of its stage(x: -7.5, y: -50). This is inside another movie clip where electron rotates. This movie clip is called electron-anim. Finally, electron-anim is inside another movie clip called cursor. Cursor has the following actionscript applied to it to make it follow the mouse.

Code:
onClipEvent (load) {
startDrag(pointer,1);
}

Because electron is offset, its rotation gives the illusion that it is orbiting the mouse cursor.

The four red dots on the stage are instances of the same movie clip. This movie clip has a tween labeled "grow", where the circle increases in size, and a tween labeled "shrink", where the circle is reduced back to its original size. Also in this movie clip, on a layer on above of the tweens, is a 30x30 instance of a square with alpha set to 0. I included this invisible square so that there is a consistent bounding box regardless of the circle's current size.

So, my goal is to have the "grow" or "shrink" tweens triggered whenever electron passes over the invisible squares. I've tried looking up many different tutorials and threads on how to script this, but haven't found anything that works quite right. I hope someone here can provide some assistance. I'd really appreciate it.

Problems With Collision Detection Between Movie Clips And Text Boxes
I have a large map (movie clip) on a stage that is much smaller so that only a portion of the map is shown on the stage at a time. The map contains points of interest (movies clips) and labels (text boxes) for those points. These points and labels are dynamically created and placed on the map. The position of the map point is determined by an external XML file and the label is positioned next to the map point. Each map point links to a corresponding webpage. The map point for the page the user is on becomes the center of the map and determines the portion of the map shown.

I have been able to get the map to re-center with reasonable accuracy and I am planning on using variables from the URL or flashvars to determine what map point should be the center based on the page the user is on. The problem I am currently having is there are several labels that overlap map points or other labels. I have been attempting to use collision detection to determine which labels are overlapping and move those labels to an empty area on the map. My first attempt at collision detection was with hitTest() but this was not working. From what I found, hitTest() only works with movie clips and the labels are dynamically created text boxes. It is necessary to have the labels as text boxes because the labels need to have a background color and have a variable width to accommodate the longer text ; this didn’t seem possible with a movie clip. Below is the method I am currently trying to use:
1. Create an instance of a movie clip (pre-existing movie clip from the library, containing a dot) for each map point and place according to the information in an external XML file.
2. Create text boxes for each label and place the text boxes next to the appropriate map point
3. Determine which labels overlap other labels or map points
4. Determine if the labels that overlap can be moved above or below their current position without causing new collisions.
5. Check to see if the new position of the labels that need to be moved will overlap with other labels that are being moved. If they do, find a new place for the label then move it. If not, just move the label.

There are several problems with the current method:
1. For the best results I have to check each corner of every label and map point to see if it overlaps with other labels. This results in lots of if-statements with the code in the if-statements being very similar.
2. While loops and functions do not work so there is lots of repeated code. When I use while loops, the Flash movie runs very slow and eventually crash the program before anything is placed on the map. When I use functions, I am unable to access variables inside the functions and I end up with a blank map when I test the movie. I thought this might be a variable scope problem and declared my variables outside of the function but this didn’t fix the problem.
3. Several label overlaps are not detected. I was thinking this has something to do with the depths of the labels because collisions only seem to be detected with labels that were placed after the label being tested but I don’t know if or how this problem can be fixed.
4. I can’t seem to get the labels to a point where all labels are not overlapping no matter where the map is centered. I can usually manage to get one portion of the map to look decent but as soon as I re-center the map the labels are overlapping in that portion worse than they were before.

I have searched extensively on the internet and can only find collision detection used for creating games. As you can see, I have been unsuccessful at tailoring the gaming solutions to my problem. What I would appreciate is any suggestions, links to websites or tutorials, or anything else that might be helpful in solving my problem. Thank you in advance for your help.

Movie Clip Collision Detection
i have a lighter which i created and for an interface i would have 5 ropes, one for each of my menu options.

what i need is when the lighter is on and the flame movie clip is visible i need a collision detection for when the flame touches one of the ropes, then my movie will go to the frame where that option lies.

Multiple Movie Clip Collision Detection
I have many instances of a movie clip (by using duplicateMovieClip) on my stage, each with a name of "clip1", "clip2", "clip3" etc.
I have many instances of another movie clip, like the one above, but all derived from a different original movie clip. They're named "something1", "something2" etc.
I want to put an "if" statement that performs a "hitTest" between one of the "something" movie clip instances and ANY of the "clip" instances.
This is the code I have inside the onClipEvent (enterFrame) of the "something" instance:
onClipEvent (enterFrame) {
if (this, hitTest(_root.varClip)) {
this.removeMovieClip();
}
}
and I have this code in a frame on the _root level
for (var i = 1; i<=3; i++) {
_root.varClip = ["clip"+i];
}
Nothing is working this way. Is there some other way that I can check the collision using arrays?
Am I mixing up the paths?
I'd really appreciat some help with this. I feel like I'm so close already.
Thanks
Kevin

Adding Collision Detection To A Custom Movie Clip
Hey, guys. I've created a custom movie clip object (by extending the movieclip class) and instantiated a number of them for a game I'm making. From what I've read, you can add collision detection to the custom object. Before hand, with each frame I'd loop through every single object and see if something hit it. As a matter of fact, I did that for one game I just made and everything worked beautifully. However, can't I do something like


Code:


class Something extends MovieClip {
var someVar;
function Something (x,y,someVar) {
this._x = x;
this._y = y;
this.someVar = someVar;
}
function hitTest(someOtherObject) {
this.removeMovieClip();
}
}



If I can do this, the question becomes, how do I pass in the object to do the test? Do I pass it in as a member variable when I attach the movie clip? For example, I pass in values for the constructor with

_root.attachMovie("instance1","Something",this.getNextHighestDepth,{x:100,y:100,someVar:12});

where the final parameter is the initial values. Should I pass in all objects that could possible hit the attached movie clip then check within hitTest? Any help would be greatly appreciated.

[F8] Help With Attached Movie Clips?
I'm trying to control an attached movie clip (button2_mc) which has been attached by a previously attached clip (button1_mc). Is this possible? What am I missing here? Here's my code below (on frame 1 of timeline):


PHP Code:



attachMovie("button1","button1_mc",1,{_x:50,_y:100})

button1_mc.onRelease = function () {
    attachMovie("button2","button2_mc",2,{_x:100,_y:150})
}

button2_mc.onRelease = function () {
    attachMovie("button3","button3_mc",3,{_x:150,_y:200})
}

[CS3] Attached Movie Clips Always On Top
I have a movie clip that is made up of several buttons. Which attach a movie clip to the root-think of this as the bottom. I have a movie clip that covers the bottom that goes on top after a user clicks-think of this as the top

My problem is that the attached movie clips from the bottom still go on the top. Is there anyway around this?

Deleting Attached Movie Clips
Hello all,
I am having trouble deleting an attached movie.

I have a function in the first frame on the main timeline that attaches a movie to another MC this works fine...

In the attached movie I have an on clipEvent enterFrame script that has variables that change during the scripted animation of itself. IE the atached movie is told to move down the y axis and I have variables that show me the y value. These variables successfully do this (I can see it in the output window)...

However, I want the attached movie clip to delete itself once it exceeds, say 80, along the y axis. This does not work!
I use this in the movie clip:

thisYPos = this._y
if (this._y>80) {
this.removeMovieClip();
_root.offScreen++;
}

I can see the value increase of thisYPos past 80 and nothing happens!!!!!!!!

WHY?WHY?WHY?WHY?WHY?WHY?WHY?WHY?WHY?WHY? : (

If anyone thinks they can help please let me know!

SS

Controlling Attached Movie Clips
Is there some reason I cannot attach a movie clip with code like this:

for (count=0; count < itemCount; count++){
canvasMC.attachMovie("itemMC", "item" add count, count);
}

and then control that movie clip using:

canvasMC["item" add count].gotoAndStop("stopped");

?

This doesn't seem to work...is it a problem to control attached movie clips?

Thanks in advance...

Attached Clips Way Above Rest Of Movie
Hi all,

I currently have am creating a game where you shoot at targets that randomly appear. I have them set to be randomly generated via an attachMovieClip object, and all works well... EXCEPT that whenever it generates the clip from the Library, the instance is WAY above the rest of movie!

This means that my custom-crosshairs cursor, for instance, is behind the target and thus the user cannot mouseDown and shoot it.

Ack... any ideas what to do?

Thanks!
- wobbly

Attached Movie Clips Have Different Registration?
I've been duplicating and attaching movie clips and I'm getting strange positions when I attach. It seems that attaching changes the registration from center to upper left.
Is that right?

Duplicating Attached Movie Clips
has anybody heard of using the duplicateMovieClip action on an attachMovieClip? i want to set up a menu system that gets a submenu attached to it on roll over, but duplicated as many times as there are items in an array. does that make sense? does anyone have an answer or a dynamic AS alternative?

Charles

Removing Attached Movie Clips
here is the code I am using to attach an exported movie clip from the library called birdMC:


PHP Code:



createEmptyMovieClip("emptyBird", 16);
_root.stamps.birdb.onPress = function() {
        _root.actions.penmode = "stamp";
        c = c+1;
    emptyBird.attachMovie("birdMC", "newBird"+c, 5000+c, {_x:_root.emptyBird._xmouse, _y:_root.emptyBird._ymouse});
    var copyBird = _root.emptyBird["newBird"+c];
    startDrag(copyBird);
    copyBird.onPress = function() {
        if (_root.remove == true) {
            copyBird.removeMovieClip(this);
            _root.actions.penmode = "stamp";
            c = c-1;
        } else {
            startDrag(copyBird);
            _root.actions.penmode = "stamp";
        }
        copyBird.onRelease = function() {
            stopDrag();
            _root.actions.penmode = "draw";
            _global.current = this;    
        };
    };
};




my question is, what script would I put on a button inside of the birdMC movie clip that would cause the movie clip to be removed? I would like it to only remove that instance of the movie clip, no other instances that may be on the stage.

thanks in advance....

Naming Attached Movie Clips?
Hello,

I think my brain may explode soon, I'm so stuck!

I'm trying to create an swf that will feature a menu of button shapes that when pressed will call for a movie clip from the library to be placed onto the stage...
I've managed to do something that works by just putting in default names and values...but I know it's not the proper way to do it.
I'm attaching what I've done so far, but what I need to know is the code for creating a new movieclip name for the attached movie, and how to ammend what I've done so that more than one instance of the shape can be placed onto the stage...

I hope that makes sense? The attached movie should make things clearer.
I'd appreciate any help from anyone who can work out what I mean!

Thanks in advance

Loading In Attached Movie Clips
hi im working on a site which uses attachMovie(); quite heavily.

on the linkage i have them exporting on frame one.
i made a preloader - just a simple one using _root.getBytesLoaded()

the problem is that the loaders graphics do not appear until all the attached clips have loaded in - basically at around 90% which is pretty useless.

is there any way (tutorials, commands or examples) of how to manage these attatched clips in the loader. or anyway that i could get the loaders graphics to appear from the start. (only a text box and a bar tweening nothing heavy there).

alternatively i could put a loader at the beginning of each clip i attach - but that strikes me as a bit of a pain, and id rather load all the sites info at once.

Aligning Attached Movie Clips
hi

Im trying to get a bunch of attached movie clips have a differnt widths for certain clips

var words_list = [["a"], ["a", "-", "b", "ou","-" "t"],["we","-","jk"-"h"]

Im attaching each letter into a seperate movie clip.
When I get to a "-" sign I want to clip to be smaller in width. The problem I`m having is that all the clips are the same distance apart and I need them to be different widths. I think the problem is the "vari" variable, but I`m blowed if i can figure it out!


for (i=0; i<myLength; i++) {
vari = i*100;
let = words_list[1] //"about" has two "-" in it 1st and 4th position in string

_root.attachMovie("letter_mc", "letter"+i, 900+i);
_root["letter"+i].lett_mc.lett_txt = let;
_root["letter"+i]._x = _root["letter"+i]._x+vari;
_root["letter"+i]._y = 400;

}

Unloading Attached Movie Clips All At Once
I've used attachMovie() to add many copies of the same clip to my stage (which have various other actions on them). They can also each be individually dragged into a trashcan, which unloads whatever movie clip has been dragged over the trash can. However, I haven't yet figured out how to unload all of the clips that have already been attached all at once. I thought maybe a for loop would be the answer here, and so did one of the java programmers here at my job, but we couldn't figure out how to make it actually work.

Here is the code I have on the main timeline:


Code:
_global.icopy = 1;


//functions//

function RotateDrag(whichPiece) {
if (Key.isDown(18)) {
_root[whichPiece]._rotation += 30;
} else {
startDrag(_root[whichPiece], false, 20, 20, 780, 580);
}
}


function dup() {
var nextDepth = _root.getNextHighestDepth();
icopy = icopy+1;
attachMovie("linkRed", "movRed"+icopy, nextDepth);
}


function dup2() {
var nextDepth = _root.getNextHighestDepth();
icopy = icopy+1;
attachMovie("linkGreen", "movGreen"+icopy, nextDepth);
trace ("movGreen" + icopy)
}



//button functions//


btnDup.onRelease = function() {
dup();
};




btnGreen.onRelease = function() {
dup2();
};

btnClear.onRelease = function() {
for (icopy = 1; icopy<15; icopy++){
unloadMovie("movGreen" + blah);


}

}


And I've attached the file below. Any insight into this problem would be greatly appreciated.

[F8] Randomly Attached Movie Clips
Ok, I'm sure this has a simple solution, and I suspect it involves using an array, but I'm not sure...

What I'm trying to accomplish is to have a movie clip randomly seleted and attached to the main movie. I have the for loop which will randomly generate the numbers, and I'd like to have that result concatenated with "mcC1Exercise" for attaching, so it would be mcC1Exercise01, McC1Exercise12, and so on. Here is the code I have so far.


Code:
function newExercise():Void {

// this function randomly selects a number
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
return randomNum;
}
for (var i = 0; i<10; i++) {
var nRand1:Number = randRange(1, 10);
}
}

function displayExercise():Void {
this.attachMovie("mcC1Exercise", "Exercise", this.getNextHighestDepth());

};


I've tried simply just adding the nRand1 to the end of "mcC1Exercise" but no movie loads. What should I do to make this work?

Thank you...

Targetting Attached Movie Clips
Hi , hope someone can fix this, it's prolly something rather simple , but I'm blinded by the simplicity

Roughly got this code (edited for viewing pleasure):


Code:
for (i=0; i<5; i++) {
planet=attachMovie("star", "mc_star"+i, 100+i);
}


now , after this for loop , let's say , I want to call the third attached star and set it to invisible ... how do I call it ?


Code:
planet["mc_star" + 2]._visible = false;


doesnt seem to do the trick.

[MX] Preloading Attached Movie Clips
I apologize for this but I can't seem to find anything regarding my sitch..Please help!

I built a movie using using mc_tweens utilizing the attachMovie. What I have so far is a "mainMc" with all of the attached movie clips scripted there. On the main timeline I have a setInterval that attaches and loops the "mainMc" a specific number of times. The swf file is pretty large and I would like to add a preloader to the whole swf. I'm familar with loading external swfs into an empty movie clip and using a preloader there but not for attached movies. Is there a way that I can preload these attached movie clips? Am I missing something here?


I made another movie that pulls in this swf with the attached movies and made a preloader.... the movie came in but the preloader didn't work. Does anyone know a good way to go about this. Any help would be great!

Thanks

Removing Attached Movie Clips
Hey again.

I used the Attach movie clip method to create bricks in a game i'm making. The problem is, I don't know how to remove them. Any help would be appreciated.


Quote:




var ref:MovieClip = _root.attachMovie("brick", "brick"+movieNum, movieNum);

//line them up
ref._x = 58 + ref._width * row;
ref._y = 50 + ref._height * col;

Randomly Attached Movie Clips
Ok, I'm sure this has a simple solution, and I suspect it involves using an array, but I'm not sure...

What I'm trying to accomplish is to have a movie clip randomly seleted and attached to the main movie. I have the for loop which will randomly generate the numbers, and I'd like to have that result concatenated with "mcC1Exercise" for attaching, so it would be mcC1Exercise01, McC1Exercise12, and so on. Here is the code I have so far.

I've tried simply just adding the nRand1 to the end of "mcC1Exercise" but no movie loads. What should I do to make this work?

Thank you..








Attach Code

unction newExercise():Void {

// this function randomly selects a number
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
return randomNum;
}
for (var i = 0; i<10; i++) {
var nRand1:Number = randRange(1, 10);
}
}

function displayExercise():Void {
this.attachMovie("mcC1Exercise", "Exercise", this.getNextHighestDepth());

};

Coding Attached Movie Clips
So I want to have a movie clip appear on the screen when I click the mouse. So i click all over the screen and there are movie clips everywhere.
Then when I click A, I want another movie clip to appear in each movie clip, and move across the screen.

I can get the second movie clip to appear ontop of the first movie clip, but only the most recently placed one will move.







Attach Code

onMouseDown = function()

{



box = attachMovie("path", "path" + _root.getNextHighestDepth(), _root.getNextHighestDepth(), {_x:_root._xmouse, _y:_root._ymouse})



bullet= attachMovie("bull", "bull"+_root.getNextHighestDepth(), _root.getNextHighestDepth(),{_x:box._x, _y:box._y})
bullet.onEnterFrame = function()
{

bullet._x+=10

}

}

Targeting Attached Movie Clips
I'm having trouble figuring out how to target a series of movie clips i'm attaching to my movie.

Here's the idea:
I'm loading some xml for a slideshow and i'm generating a series of dots at the bottom of the screen to indicate how many steps are in the slideshow and the circle is meant to highlight your current position as you step through the presentation.

the MC for the dots is two keyframes with a different color and a stop action on each frame.

Here's the rundown of the code:

1. There's nothing weird here, i'm just bringing the xml in

Code:
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("xml/data.xml");
2. Here is the loadXML function i reference in the xml.Data.onLoad above:

Code:
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
description = [];

// the total and stepArea vars are used to space the dots. total is also used in a loop.
total = xmlNode.childNodes[1].childNodes.length;

stepArea = (Stage.width/2) - Number(titleBar_mc.stepContainer_mc._x);

// here is where i'm attaching the dots.
for (i=0; i<total; i++) {
//render the step dots
var q = stepContainer_mc.attachMovie("step", "step"+i, i);
q._x = i*(stepArea/total);
q._height = (stepArea/total)/4;
q._width = q._height;
}
firstImage();
} else {
content = "file not loaded!";
}
}
Okay so now i have some dots with the instance names, step0, step1 etc. right? And at the end of my loadXML function you see the firstImage(); function. This is where my problem is, how do i target the first (step0) instance? I have no problem when I write "step0.gotoAndStop(2);" but I need to figure out how to use a variable to keep moving it along when i make my next and last functions for the slideshow.

3. Here is the firstImage function:

Code:
var p = 0;
function firstImage() {

image_mc._alpha = 0;
image_mc.loadMovie(image[p], 1);
//this is where my problem is. how do i target the step the same way i target the image? do i have to go back and do something in the loadXML for loop?
stepContainer_mc.step[p].gotoAndStop(2);
}

Masking Attached Movie Clips
Hi there -

i am trying to apply a mask to some attached movieclips.

i am having some problems, i am assuming due to the depth difference between the mask (placed on stage hence with a negative depth) and the attached movie clips (positive depth).

i have tried swapping depths and also assigning a higher depth to the mask (using getNextHighestDepth), but nothing seems to work.

does anybody know of any way around this?

ta

(btw...is it possible to attach a mask?)

Nesting Attached Movie Clips
is there a cleaner way to attach movie clips than this type of syntax?

_root.attachMovie ("Frame", "frame", 60);
frame._x = 375;
frame._y = 375;

_root.attachMovie ("BeigeGrad", "bgrad", 10);
bgrad._x = 378;
bgrad._y = 850;


by say doing it similar to this?

_root.attachMovie ("Frame", "frame", 60),("BeigeGrad", "bgrad", 10);

frame._x = 375;
frame._y = 375;

bgrad._x = 378;
bgrad._y = 850;

Attached Movie Clips And Scrollbar ? ? ? ?
Hello everyone,

I am not that good in flash and i would appreciate any help on this.

I want to know if there is a possible way to have a scrollbar in attached movie clips ....

let me give you an example of it to make it more clearly.
I have some buttons that each button attaches some movie clips in the main.swf (the movie clips are some sort of big square) so when are about 4 attached movie clips in the main.swf the last movie clip can`t be seen.
How can i add a scrollbar or something else so i can see after the 3rd movie clip?????

If there are more than 3 movie clips to be attached i can`t see the movie clips after the 3rd one.....

Can anyone help me with that?
Thanx

[MX] Masking Attached Movie Clips...
Hello!

I was wondering if anyone's come across this problem...

I have a dynamically generated menu bar set to scroll from left to right, and everything works fine... until I add a mask to show only the section of the menu in the display menu. The trouble is, when I do this, the dynamic text no longer shows... it loads, but doesn't show. Everything is exactly the same, except the text doesn't show when I add the mask.

Sound familiar? Suggestions? Hints?

Thanks!

lrhb

OnEnterFrame For Attached Movie Clips
I am dynamically creating clips from a library symbol and need to assign an onEnterFrame event to each clip as it's created but I'm having a lot of hassle!

The code (which is within a function, if that matters!) looks like so:


Code:
for (i=0; i<arrImages.length; i++) {

newPhone = phones.attachMovie("phone", "phone"+i, i);
newPhone.loadMovie("images/phones/"+popImages[i]);

newPhone.onEnterFrame = function() {
this.test += 1
trace(this.test);
}

}
The phones are being attached and the images are being loaded into them yet the onEnterFrame event doesn't seem to be occurring. Any idea why?

Hittest On Complex Movie Clips (collision)
Hi!

I have problems testing the collision of two movieclips. My problem is that the collision is detected by the bouding boxes of the movieclips and not the actual surface of the shapes of the movieclips. This way it says they collide, even when they don't touch eachother (only the bounding boxes). I Searched for all kinds of possibilities to solve this, but I couldn't. If somebody has a creative idea, PLEASE let me know!!!!

thanx!

Robert

Making Movie Clips React To Collision
I am trying to get the effect of a snooker pack being broken up with a cue ball for my website, is there a way using action script i can achieve this. Also, is it possible to use a SWF as a background in Dreamweaver?

Dynamic Text In Attached Movie Clips
Hi

I am trying to construct a game which has 5 columns of 20 symbols each.
I am using Actionscript to attach these 100 symbols as Movieclips and then selecting a random frame within each movie clip to get a random symbol.

This first part all works fine.

The problem is that I also want to number these symbols from 0 - 99 and I have tried a similar approach using by attaching Movieclips which have a Dynamic Text field that I am then trying to update for each clip.

This part doesn't work - I have put a test value in the dynamic text movie clip and this displays so the clips are attaching and are being positined correctly. What is not happening is the updating of the value for each loop of i. The Movieclip that gets attached is called "number" and its Dynamic Text field is called "display".

Here is the code:

code:

initGame();
// stop ();
function initGame () {
// define right hand column & bottom row coords
firstcol = 470;
firstrow = 500;
// define deltas from start point
x = 0;
y = 0;
// loop 100 times to attach signs
for (i=0; i<100; i++) {
// attach movieclip for each sign
attachMovie("signs", "sign"+i, 100+i);
// move clip to correct coordinates
clip = _root["sign"+i];
clip._x = firstcol-x;
clip._y = firstrow-y;
// movie clip to random frame
clip.gotoAndStop(int(Math.Random()*12+1));
// THIS NEXT BIT DOESN'T WORK!!
// attach movieclip for each number
attachMovie("number", "num"+i, 300+i);
// set dynamic text field
display = i;
// move clip to correct coordinates
clip = _root["num"+i];
clip._x = firstcol-x-35;
clip._y = firstrow-y;
// increment deltas & start new column
// if necessary
y = y+25;
if (y>480) {
x = x+70;
y = 0;
}
}
}



Any help would be most gratefully appreciated!

Thanks,

Adam

Duplicating A MovieClip Which Contains Attached Movie Clips..
When i duplicate a movieclip which cotnains attached movieclips, the attached movieclips are not duplicated... whats the best way around this?

Cheers in advance

[F8] Targeting Buttons In Attached Movie Clips
I'm creating a slidshow-type engine and i'm running into problems with targeting buttons in the attached movie from the main timeline of the main movie. Right now there are only two movies clilps to attach. The first movie clip works fine, but when I go to the next movie clilp, it doesn't work. Same when I go back to the first movie clip, the button no longer works. I'm try to keep all my code in one place, I have just added added a few trace commands, so you can tell if the code in the main timeline, or the attached movie is being triggered.

I have attached the file and the code.

I have a feeling that the problem is in either in the "FADE IMAGE AND TEXT" section or the "CONTROL" section.



Code:
/* -----------------------------------------------
-------------- INITIAL SETUP ---------------------
--------------------------------------------------*/
import mx.transitions.Tween;
import mx.transitions.easing.*;
var i = 0;
var sideBarContent = new Array();
var stepTitleContent = new Array();


// Set Movie Title
movieTitle = "XO Communications | How to Read Your Bill";
//--------------------- End Initial Setup




/* -----------------------------------------------
-------------- CONTENT ---------------------------
--------------------------------------------------*/
stepTitleContent[0] = "<b>Remittance Page</b>";
sideBarContent[0] = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam suscipit. Cras tristique, lorem sed aliquam volutpat, mauris diam blandit nisi, ut venenatis odio elit eu dui. Donec ullamcorper risus elementum elit. Morbi blandit dolor. Ut leo mi, convallis vel, dapibus et, pellentesque vitae, nisl. ";

stepTitleContent[1] = "<b>Statement of Account</b>";
sideBarContent[1] = "Suspendisse non elit. Pellentesque at ipsum. Suspendisse nisl. Ut fringilla ante a massa. Curabitur cursus, elit fringilla porta blandit, purus nulla dictum sem, eget imperdiet risus augue non nisl. Vestibulum massa mauris, dictum in, luctus ut, ultricies blandit, leo.";
//--------------------- End Content



/* -----------------------------------------------
-------------- FADE IMAGE AND TEXT ---------------
--------------------------------------------------*/
// set text mask-----------
this.sideBarText.setMask(this.sideBarMask);

// define slide-in function
sideTextSlide = function(){
var slideTween = new mx.transitions.Tween(this.sideBarMask, "_x", mx.transitions.easing.Strong.easeIn, -187.9, -14.0, 0.5, true);
}

// define fade-in function
allFadeIn = function(){
this.attachMovie("image"+i, "mainImage", this.getNextHighestDepth(), {_x:213.9, _y:53.0});
this.mainImage.setMask(this.imageMask);
var fadeTween = new mx.transitions.Tween(this.mainImage, "_alpha", mx.transitions.easing.Strong.easeIn, 0, 100, 0.5, true);
fadeTween.onMotionFinished = function(){
sideBarText.textArea = sideBarContent[i];
sideTextSlide();
};
}
//--------------------- End Image Fade Mask





/* -----------------------------------------------
-------------- CONTROL ---------------------------
--------------------------------------------------*/

// First actions
allFadeIn();
var movieLength = (sideBarContent.length-1);
this.sideBarText.textArea = sideBarContent[i];
this.stepTitle = stepTitleContent[i];

// Next Button
nextButton.onRelease = function(){
if (i < movieLength){
i++;
stepTitle = stepTitleContent[i];
sideBarText.textArea = " ";
removeMovieClip(mainImage); //dump loaded movie
allFadeIn();
}
}

// Previous Button
prevButton.onRelease = function(){
if (i > 0){
i--;
stepTitle = stepTitleContent[i];
sideBarText.textArea = " ";
removeMovieClip(mainImage); //dump loaded movie
allFadeIn();
}
}


//--------------------- End Navigation Buttons



/* -----------------------------------------------
-------------- MORE INFO -------------------------
--------------------------------------------------*/
this.attachMovie("moreInfo", "moreInfoBox", this.getNextHighestDepth(), {_x:295.5, _y:195.5});
moreInfoBox._visible = false;

loadInfo = function(){
moreInfoBox._visible = true;
var revealInfoW = new mx.transitions.Tween(moreInfoBox, "_width", mx.transitions.easing.Strong.easeIn, 0, 532, 0.5, true);
var revealInfoH = new mx.transitions.Tween(moreInfoBox, "_height", mx.transitions.easing.Strong.easeIn, 0, 285, 0.5, true);
moreInfoBox.moreInfoBlocker.useHandCursor = false;
}

// This button in in the first attached movie
mainImage.payStub_btn.onRelease = function(){
trace("hit buttom from main movie");
loadInfo();
}

// This button is in the second attached movie
mainImage.statementInfo_btn.onRelease = function(){
trace("hit buttom from main movie");
loadInfo();
}

moreInfoBox.moreInfoBlocker.onRollOut = function(){
var hideInfoW = new mx.transitions.Tween(moreInfoBox, "_width", mx.transitions.easing.Strong.easeIn, 532, 0, 0.5, true);
var hideInfoH = new mx.transitions.Tween(moreInfoBox, "_height", mx.transitions.easing.Strong.easeIn, 285, 0, 0.5, true);
}

//--------------------- End More Info

Pre-load Question - Attached Movie Clips
I'm not very experienced in flash, and I have been asked to re-do a section of a clients website. they needed display and navigation for listing over 70 of their advertisers and ads. I'm about 90% done now, and I'm realizing that the way I've set it up might be utterly wrong.

I have it all contained in a single swf, which is only 3 frames long. 1st frame for the main menu, 2nd frame for the ad listings, and 3rd frame for the category listings. For each ad and category, i've created movie clips of the main layout and added linkage so that they can be attached at will.

the problem... this creates a huge file size, and the movie won't even show up until the entire swf is loaded.

Any suggestions? I'd like to load each ad as it is clicked, but would I need to create a separate swf to do this?

Any help would be greatly appreciated, as the deadline is closing in fast and I am already over the estimated hours.

here's what I have so far to give you a better idea...
http://www.skateaz.com/redbook/ad.html

How Do I Target These Attached Movie Clips In For Loop
i want to when i click a button delete all these 50 smoke movie clips from the movie... how?
unloadMovie(_root.smoke_mc+j")????


_root.smoke_int = setInterval(createSmoke, 50);
function createSmoke() {
for (j=0; j<50; j++) {
var newSmoke = attachMovie("smoke", "smoke_mc", 500+j, {_x:400, _y:400});
newSmoke._x = (random(5)+70);
newSmoke._y = (random(100)+185);
newSmoke._xscale = (random(20)+50);
newSmoke._yscale = (random(120)+50);
newSmoke._alpha = random(5);
newSmoke.gotoAndPlay(random(20)+1);
}
}

[F8] OnEnterFrame Not Working With Attached Movie Clips
I cannot get an onEnterFrame function that attaches a movie clip to allow a button inside the attached movie clip to work. It attaches the clip but does not allow functionality of the clip. When a button is on the stage to attach the clip it works fine. File is attached onEnterFrame function is commented out. Thanks

Selecting And Deselecting Attached Movie Clips
I made a simple flash movie that allows the user to create circles (using attachmovie) and move them around the screen and adjust the size with a slider. My problem is that I can't seem to figure out how how to let the user click on an individual circle movie clip to select it so they can adjust the size of that circle only. Then they would click off of the movie clip to deselect it. There's no handy .onPressOutside event handler. I just sort of need a plan of attack -- basic logic of how to select/deselect attached movies. Thanks!

Targeting Dynamically Attached Movie Clips
How do I target a movie clip that is added dynamically to another movieclip? I created the movieclip called masker and I have added 50 circles to the masker movie clip. How to I target the each of the movie clips that are nested inside of masker?

ActionScript Code:
var home:MovieClip = _root;

function randRange(min:Number, max:Number):Number {
    var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
    return randomNum;
}
this.createEmptyMovieClip("masker", 10);

var space = 0;

for(var i:Number = 0; i < 50; i++) {
    var yspace:Number = randRange(0, 245);
    var xspace:Number = randRange(0, 505);
    var scale:Number = randRange(0, 20);
    var timeWait:Number = (randRange(0, 1))*.5;
    masker.attachMovie("mc_circle2", "mc" + i, i+1000, {_y:yspace, _x:xspace, _xscale:scale, _yscale:scale});
//this is where I am trying to target the movie clips and I get an actionscript error.
    masker.["mc"+i].scaleTo(200,4,"easeInBack", timeWait);
    trace("x: " + xspace + " y: " + yspace + " scale: " + scale);
}

How To Position Duplicated/attached Movie Clips
Hi there.

I have a series of MC's being attached dynamically to my Flash file, displayed horizontally.

I am unable to specify where the MC's sit along the X axis. I have been able to position the MC's on the Y axis, though. Here's the function that draws the MC's


Code:
function topNav(navNode) {
for (var n = 0; n<navNode.childNodes.length; ++n) {
tClip = this.attachMovie("menuClip", "menuClip"+n, n);
tClip.navText = rootNode.childNodes[n].childNodes[2].childNodes[0].nodeValue;
tClip._x = this["menuClip"+(n-1)]._x+this["menuClip"+(n-1)]._width;
tClip._y = 415
tClip.choice = n;
tClip.pageNode = rootNode.childNodes[n].attributes.Num;
}
}
Any ideas on how I can set the orginal X cordinate?

Adding Easing To Attached Movie Clips
I've attached some MovieClips to the stage by looping through an array. (dreamarray) I'm trying now to add easing to each of these MovieClips. I found a tutorial, but can't seem to translate their tutorial over to my file. In the released() function...i am creating a temp variable "t" to hold each of my dream elements. The t.xPos and t.yPos are undefined when I trace them after clicking on them. I would appreciate any help!

Right now I have t.xPos = dream._x --- I'm sure this needs to be changed

import mx.utils.Delegate
import mx.transitions.Tween;
import mx.transitions.easing.*;

var numClouds:Number = 35;
var fl:Number = 250;
var gravity:Number = .5;
var vx:Number = 0;
var vy:Number = 0;
var vz:Number = 0;
var friction:Number = .97;
var vpX:Number = Stage.width / 2;
var vpY:Number = Stage.height / 2;
var vpY:Number = 400;
var home:MovieClip = this;

var dreamarray:Array = new Array();
dreamarray[0] = "dreamone";
dreamarray[1] = "dreamtwo";
dreamarray[2] = "dreamthree";
dreamarray[3] = "dreamfour";
dreamarray[4] = "dreamfive";

var dreamarrayX:Array = new Array();
dreamarrayX[0] = 0
dreamarrayX[1] = -1800;
dreamarrayX[2] = 2000;
dreamarrayX[3] = 100;
dreamarrayX[4] = -1700;

var dreamarrayZ:Array = new Array();
dreamarrayZ[0] = 0;
dreamarrayZ[1] = 500;
dreamarrayZ[2] = 1000;
dreamarrayZ[3] = 1500;
dreamarrayZ[4] = 2000;

function init() {
for (var i:Number = 0; i<dreamarray.length; i++) {
var dream:MovieClip = attachMovie(dreamarray, "dreamarray" + i, i);
//var dream:MovieClip = attachMovie("dreamone", "dreamone" + i, i);
//dream.x = Math.random() * 1600 - 800 + dreamoffset;
dream.x = dreamarrayX;
dream.y = 50;
dream.z = dreamarrayZ;
dream.onPress = released;
}
}

function inittwo() {
//set Number to more than number of dreams
for (var j:Number = 20; j<numClouds; j++) {
var cloud:MovieClip = attachMovie("cloud", "cloud" + j, j);
//tree.x = 400;
cloud.x = Math.random() * 2000 - 800;
cloud.y = 50;
cloud.z = 0 + cloudoffset;
cloudoffset += 600;
}
}

function released() {
for (var i=0;i<dreamarray.length;i++){
//var t:MovieClip = home["dreamarray"+i];
var t:MovieClip = dreamarray;
//These t. values are undefined when I click on one of the attached dreamarray MovieClips
t.xPos = dream._x;
t.yPos = dream._y;
t.theScale = dream._xscale;
if (dream != this._parent)
{
var tw:Tween = new Tween(t, "._x", Strong.easeOut, t._x, 300, 100, true);
}
trace(t);
trace(t.xPos);
trace(t.yPos);
}
}


function onEnterFrame():Void {
//if (dreamarray4.z >= 500 && Key.isDown(Key.UP)){
if (zdepth < 55 && Key.isDown(Key.UP)){
vz -= 1;
zdepth += 1;
}

//if(dreamarray4.z >=2000 && Key.isDown(Key.DOWN))
if(zdepth > 0 && Key.isDown(Key.DOWN))
{
vz += 1;
zdepth -= 1;
}

//Killed side to side motion
/*if(Key.isDown(Key.LEFT ) )
{
vx += 1;
}
if(Key.isDown(Key.RIGHT))
{
vx -= 1;
}
if(Key.isDown(Key.SPACE))
{
vy += 1;
}
*/


vy -= gravity;
vx *= friction;
vy *= friction;
vz *= friction;
for (var i:Number=0;i<dreamarray.length;i++) {
//i think there is a error here
var dream:MovieClip = this["dreamarray" +i];
dream.x += vx;
dream.y += vy;
dream.z += vz;
if(dream.y < 50)
{
dream.y = 50;
vy = 0;
}

/*if (dream.z <= -fl) {
//delete dream.z
dream.z_visible = false;
}
else if(dream.z > 3000 - fl)
{
dream.z._visible = true;
}
*/

if (dream.z <= -fl) {
//delete dream.z
dream.z._visible = false;
}
else
{
dream.z._visible = true;

var scale:Number = fl / (fl + dream.z);
dream._xscale = dream._yscale = scale*100;
dream._x = vpX + dream.x * scale/2;
dream._y = vpY + dream.y * scale/2;
//dream._x = dream.x * scale/2;
dream._alpha = scale * 60 + 40;
dream.swapDepths(-dream.z);
}
}
for (var j:Number=0;j<numClouds;j++) {
var cloud:MovieClip = this["cloud" + j];
cloud.x += vx;
cloud.y += vy;
cloud.z += vz;
if(cloud.y < 50)
{
cloud.y = 50;
vy = 0;
}
if (cloud.z <= -fl) {
cloud.z += 5000;
}
else if(cloud.z > 5000 - fl)
{
cloud.z -= 5000;
}

var scale:Number = fl / (fl + cloud.z);
cloud._xscale = cloud._yscale=scale*200;
cloud._x = vpX + cloud.x * scale;
cloud._y = vpY + cloud.y * scale;
cloud._alpha = scale * 60 + 40;
cloud.swapDepths(-cloud.z);
}
}

init();
inittwo();


stop();

Flash Mx: Probs With Masking Attached Movie Clips
hey, thanx for stopping by! i have a quick question...

how do i mask an attached movie clip(mc called by attachMovie())?

what i mean by this is... i know how to create a mask layer. this mask layer works for all mcs that i dragged from the library. but this mask layer does not to work with mcs i called using the code "attachMovie()". i think it is becuz the depth of the attached mc is on top of that of the mask layer... but since i am create the mask layer on the main stage i cannot make it on top of any attached mcs... any replies are greatly appreciated. thanx in advance

Movie Clips Attached To Rollover Buttons Overlapping
Hi
Can someone help me out here?

I made a movie with 2 buttons. Each button has it's own movie clip which makes the button look like it changes shape etc. on the Rollover and then returns to it's original size on the Rollout. I did this by making a transparent button. It all works as planned except that the movie clip on the lower layer is blocked off by the other mc.

How can I fix this problem? Should I try to put a LoadMovie action on the movie clip? If so- how can I do that?

Thanks
Kat

[MX] Attached Movie Clips Being Removed When Parent Timeline Loops
I have a movie clip with the following code:


Code:
onClipEvent(load) {
stop(); onMe = false;
if(SearchArray(EnemiesSeen, "X") == null) { tileLit = false; } else {
tileLit = true;
attachMovie("Info X", "X", 1);
}
}

onClipEvent(enterFrame) {
if(tileLit) {
if(hitTest(_root._xmouse, _root._ymouse, false)) {
onMe = true;
if(_currentframe != 21) { play(); } else { stop(); }
if(_currentframe == 41) { gotoAndPlay(1); }
} else {
onMe = false; play();
if(_currentframe == 41) { gotoAndStop(1); }
if(_currentframe == 1) { stop(); }
}
} else {
gotoAndStop(42);
}
}

onClipEvent(mouseDown) {
if(onMe && tileLit) {
// do stuff
}
}
This movie clip is a button-like tile that gives information when appropriately "lit" (when that information is applicable.) The tile's timeline is 42 frames long, with the frames 1-21 as "on roll in" animation and 22-41 as "on roll out" animation, and the last frame (42) as a dimmed out version used when the tile is inactive - all of this works fine.

The problem is that when the "tileLit" condition is true, the movie clip attaches another movie clip which seems to be removed if the parent movie clip reaches the end of it's timeline. The parent clip loops, as normal, but the child clip (which provides the actual information) is lost (I've done trace checks to ensure that it's not simply being hidden somewhere). Is this normal behavior for a movie clip, or is there some problem that I just can't seem to root out?

Thanks in advance for your time.

Hit Detection Of Duplicate Movie Clips
Hello all, I am new here and I posted this question on the general flash help and then I found this forum--so I will try reposting here to see if any of you flash experts can help me out. I am using Flash 4 to make games and was wondering if there is another way of doing hit detection for games when you are dealing with 2 different sets of duplicate movie clips (i.e. duplicate bullets detecting duplicate enemies) right now I limit one of the duplicates(i.e. only 5 enemies at once) and every bullet detects if it is hitting each individual clip. Unfortuneately, -ofcourse-- when you have too many clips, the speed of the game gets very slow. I was hoping there was a way to have the bullets hit detection detect any movie clip that started with a common name (clip1, clip2, clip3) so instead of writing hit detection code for ech individual clip, you could right one line that would check if the bullet is hitting any duplicates of a particular clip.
Thanks
Jeff

Loading Multiple Movie Clips Using MovieClipLoader Script Attached To A Button State
I am building a site that loads both images(using moviecliploader) and text(using loadvars.load) dynamically to a stock page(mytarget is on level5) when different buttons are pressed. My problem is that when I program a function to a button state to call more than one item it does not work.

For examle

code:
Mybutton.onRelease = function(){
myMovieLoader.loadClip(“mytarget.swf”,5); //loads the swf that has the text and image targets
myMovieLoader.loadClip(“image1.jpg”,_level5.imaget arget); //loads image to target MC on level5
myLoadVars.load(“mytext.txt”); //loads the text using myLoadVars to level5.sitetext
}


So, this does not work. If I delete any two of the lines of code it will work. The image load will work independently, the load vars will work independently, and the moviecliploader works independently.

So as a temp solution I have separated out the lines of code to different mouse actions. This does work but looks like crap because the text does not come up till the user rolls off the button, which can only confuse them.

Example

code:
Mybutton.onPress = function()[
myMovieLoader.loadClip(“mytarget.swf”,5); //loads the swf that has the text and image targets
}

Mybutton.onRelease = function(){
myMovieLoader.loadClip(“image1.jpg”,_level5.imaget arget); //loads image to target MC on level5
}

Mybutton.onRollout = function(){
myLoadVars.load(“mytext.txt”); //loads the text using myLoadVars to level5.sitetext
}


SO how would I call the moviecliploader to load...say 3 movies to different levels just by pressing a button?

EDIT: Added [ as ] tags - jbum

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