Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Location
    Ohio
    Posts
    286
    Thanks
    7
    Thanked 9 Times in 9 Posts

    attachMovie will not attach on scrolling background

    I am using this tutorial (http://www.pixelhivedesign.com/tutor...ng+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:
    Code:
    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!

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Code:
    attachMovie("titlepic_mc", "pic", 2);
    try removing "this."

    I presume pic and titlepic_mc are somewhere o nthe stage?
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #3
    Regular Coder
    Join Date
    Dec 2005
    Location
    Ohio
    Posts
    286
    Thanks
    7
    Thanked 9 Times in 9 Posts
    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/dyn...ttachmovie.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?

  • #4
    Regular Coder
    Join Date
    Dec 2005
    Location
    Ohio
    Posts
    286
    Thanks
    7
    Thanked 9 Times in 9 Posts
    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:

    Code:
    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;
                }
            };
        }
        init();
    I kind of wish the creator of the tutorial had made the tutorial to the exact example he gave...


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •