A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: attachMovie & Linkage?

  1. #1
    Junior Member
    Join Date
    May 2010

    attachMovie & Linkage?

    Hey guys.

    I’ve been using as2 for a couple years now, and I have no idea how i haven’t come across this before, but any help would be appreciated.

    I have a movie clip in the library. I went to linkage, named the instance “sol1”, and checked the “export for actionscript” box AND the “export in first frame” box.

    On the first frame, i have this code:

    if( Key.isDown(Key.SPACE) ) {
     root.attachMovie(“sol1”, “1”, {x: _ymouse, _y: _ymouse}, 3);
    Basically, i want to “create” sol1 where the mouse is when i press space.

    When i run the movie/game, it comes up with an error that says “The class ‘sol1’ could not be loaded.” When i press space it does absolutely nothing.

    If i leave the “export in first frame” box UNchecked, then it doesn’t throw up the error but it still does nothing when i press help.

    Any help would be appreciated!!

  2. #2
    Senior Member
    Join Date
    Nov 2004
    _root.attachMovie("sol1","mc1", 1,{_x:_xmouse,_y:_ymouse });

  3. #3
    Join Date
    Jan 2011

    Cow Icon

    Basically, I'll just second what gorlummeeguvnor had to say, but expand on it a bit. Ideally what you want to use is something like this:
    Actionscript Code:
    var depth = _root.getNextHightestDepth()
    _root.attachMovie("sol1", "sol1" + depth, depth, {_x:_xmouse, y:_ymouse});
    Otherwise you'll only be able to add one movie. Because multiple movies cannot occupy the same depth, when a second one is added, neither will show up. Also to be able to access the dynamically added movies from other code, they need to have unique names. Using getNextHightestDepth like this solves both these problems.

    However, it does have the problem that the added movies will end up at the top of the depth stack, which may not be desirable. This can be fixed in one of two ways.

    Firstly, you can add the movies to a container clip that is placed at the desired depth and use it's getNextHightestDepth method instead of _root's. Like so:
    Actionscript Code:
    var container = _root.attachMovie("sol_container", "sol_container", 1);
    var depth = container.getNextHightestDepth()
    container.attachMovie("sol1", "sol1" + depth, depth, {_x:_xmouse, y:_ymouse});
    Alternately, you can use do your own depth tracking and make sure that each added movie gets it's own depth and name, but remains below other items that it's supposed to remain behind.

  4. #4
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    CFA2h (respect the HEX)
    I suggest always using a variable (if applicable) to your attachMovie() method..

    it makes it easier to reference it and add actions to it..

    actionscript Code:
    var newClip = targetClip.attachMovie("linkage-name", "linkage-name"+target.getNextHighestDepth(), target.getNextHighestDepth());
    //place new clip on stage
    newClip._x = Math.random(Stage.width);
    newClip._y = Math.random(Stage.height);
    //add button events
    newClip.onPresss = function(){
        trace("My Name Is: "+this._name);

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

Click Here to Expand Forum to Full Width

HTML5 Development Center