Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving picture to different coordinates...

Status
Not open for further replies.

michanagel

Technical User
Jun 23, 2007
34
0
0
US
Hi,

I have a problem here that I can't seem to figure out with my limited action script skills...

I have this picture which has the dimensions 5599x660 and it's kinda like a moving background, it's moving to the left.

Now, when it reaches the end I want it to be replaced by the same pic...

I came up with two possible options:

1. make a duplicate of the pic movieclip and place it on stage right behind the first one and then when the first one is off stage place it right behind the second one and so on...

2. have flash duplicate the pic automatically and place it right behind the original one (I read about that option somewhere I think it's called DuplicateMovieclip)

Now I tried to go with option #1:

Code:

var xspeed:Number = 20;
function moveLeft() {

if (this._x < -5600) {
this._x = 5998;
}
this._x -= xspeed;
}


img.onEnterFrame = moveLeft;
img2.onEnterFrame = moveLeft;

--> 'img2' is place right behind 'img' on stage

So here's the problem:

1. it works, but after the first round - it goes through image 1 (img) then through image 2 (img2) perfectly and then when it's supposed to place image 1 right behind image 2 there's a space of about 100 pixels between them... I don't know why because I gave the right x coordinates in the code...

2. now when u still go on and u go through (the misplaced) image 1 (img) and then u come to the point where it's supposed to place image 2 (img2) right behind image 1 there's also a space between them but only maybe of 5 pixels...

How come that with the same pictures with the same code for both of them it's doing something different both times ?

Any help is greatly appreciated and I thank u in advance for that !!

Regards,

Mike
 
oldnewbie,

thanx for your reply.

The stage is 950x720...
 
Hi everybody,

so I managed to come up with a code that kinda works, at least it reproduces the image perfectly...

Code:

function moveLeft() {
var xspeed:Number = 15;
img._x -= xspeed;
if (img._x < 0) {
//create a loop statement to control the duplication
for(var i:Number = 0; i<100; i++){
//duplicate the movie clip
var ref:MovieClip = img.duplicateMovieClip("img"+i+"_mc",i);
//x coordinate of duplicated movieclips
ref._x += img._width*i;
}
for (h = i-1; h < i; h++)
{
removeMovieClip ("img"+h+"_mc");
} // end of for

}
}

img.onEnterFrame = moveLeft;


Still have some questions though:

1. How can I assign that the duplicated movieclips are on the same level as the original movieclip they got duplicated from ?

My image is a background, therefore on the lowest layer and unfortunately the first duplicate already is on the highest level covering everything else...

2. Until right now I was only able to come up with that 'for' function - which is working - but probably not the best solution performance wise because it generates 100 duplicates.

How can I assign that only one duplicate is produced at a time (endlessly) ?

3. I implemented the 'removeMovieclip' function. Is there any way I can control if this is actually doing what I want it to do (removing the movieclips that are off stage and not needed anymore) ??

In the Flash player, I looked under 'Debug' --> List objects but I guess it does not show removed objects....

As always thanx for your help & advise in advance...

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top