View Full Version : attachMovie will not attach on scrolling background

05-27-2009, 01:42 AM
I am using this tutorial (http://www.pixelhivedesign.com/tutorials/Endless+Scrolling+Background/) to create a header with a scrolling background and a static image set above that background.

I have got the background to scroll properly, but I cannot get the second static content to appear in the movie. The instructions in the tutorial to "Attach Content Dynamically" do not give the same kind of step-by-step information as the reset of the tutorial, so I am not sure how to add the static content.

I think my main problem is that I do not understand the theory behind how "attachMovie" works, so I do not know where to add what code and how to add it.

Here is the ActionScript I have got so far:

animator = createEmptyMovieClip('animator',1);
scrollpic_1 = animator.attachMovie('scrollpic_mc','scrollpic_1',1);
scrollpic_2 = animator.attachMovie('scrollpic_mc','scrollpic_2',2);
scrollpic_1._x = -scrollpic_1._width/2;
scrollpic_2._x = scrollpic_2._width/2;
speed = 1;
cloudWidth = 2105;
animator.onEnterFrame = function(){
scrollpic_1._x -= speed;
scrollpic_2._x -= speed;
if(scrollpic_1._x <= -scrollpic_1._width) scrollpic_1._x = cloudWidth;
if(scrollpic_2._x <= -scrollpic_2._width) scrollpic_2._x = cloudWidth;
this.attachMovie("titlepic_mc", "pic", 2);
where "titlepic_mc" is the movie clip identifier of the static image I plan to hover over the scrolling image.

Ideally, the bold code would add the movie clip at a depth higher than the code before it, but I cannot see it. I have tried removing all the ActionScript before the bold piece and still cannot see at least the static image, proving to me that I do not understand how attachMovie is supposed to work.

Can anyone tell me where I have gone wrong with the ActionScript for this?

Many thanks!

05-27-2009, 10:24 AM
attachMovie("titlepic_mc", "pic", 2);

try removing "this."

I presume pic and titlepic_mc are somewhere o nthe stage?

05-27-2009, 11:16 AM
Removing "this" did not show the static image.

"titlepic_mc" is on the stage, but I am not sure about "pic." I was trying to use this (http://flash-creations.com/notes/dynamic_attachmovie.php) information to understand the parameters for attachMovie and thought that "pic" was simply an arbitrary new title for the movie clip.

If it is not obvious already, I have no idea what I am doing when it comes to actionscript...

Would it be more helpful if I attached the .fla I am using?

06-01-2009, 01:27 AM
After downloading the swf on the tutorial and tinkering with the actionscript, I was finally able to get the static image to appear. I took further tweaking to get the logo to appear independent of the alpha of the scrolling background.

Here is the final code I ended up using:

function init () {
cloudWidth = 2105;
my_logo = attachMovie("my_logo", "my_logo", 2);
my_logo._x = my_logo._x + 170;
my_logo._y = my_logo._y + 50;
animator = createEmptyMovieClip("animator", 1);
animator._alpha = 100;
scrollpic_1 = animator.attachMovie("scrollpic_mc", "scrollpic_1", 1);
scrollpic_2 = animator.attachMovie("scrollpic_mc", "scrollpic_2", 2);
scrollpic_1._x = (-scrollpic_1._width) / 2;
scrollpic_2._x = scrollpic_2._width / 2;
speed = 1;
animator.onEnterFrame = function () {
scrollpic_1._x = scrollpic_1._x - speed;
scrollpic_2._x = scrollpic_2._x - speed;
if (scrollpic_1._x <= (-scrollpic_1._width)) {
scrollpic_1._x = cloudWidth;
if (scrollpic_2._x <= (-scrollpic_2._width)) {
scrollpic_2._x = cloudWidth;

I kind of wish the creator of the tutorial had made the tutorial to the exact example he gave...