A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: attachmovie script

  1. #1
    Junior Member
    Join Date
    Dec 2002
    Location
    canada
    Posts
    15

    attachmovie script

    HI,

    i'm really a newbie in AS2 and here is what i would like.

    I have a MC in my library that is named brick. I want it that when i press "space bar", the MC "brick" is loaded into my main scene.

    I know i have to use the attachmovie command and a kind of "linkage" but whatever i try with code and these 2, it just doesn't do anything.

    Any idea what kind of coding i should use and must i add it to the timeline or the MC?

    thanks a lot for your help

    seb

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    This should get you started
    PHP Code:
    var keyListener:Object = new Object();
    keyListener.onKeyDown = function()
    {
        if (
    Key.getCode() == 32)
        {
            
    _root.attachMovie("brick","brick",5);
            
    trace("Attached");
            
    key.removeListener(keyListener);
        }
    };
    Key.addListener(keyListener); 

  3. #3
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Hello there,

    if you want the clip being placed "once" and not creating more instances of it in the stage, use this script:

    PHP Code:
    var KeysListener:Object = new Object();
    KeysListener.onKeyDown = function()
    {
        if(
    Key.isDown(Key.SPACE))
        {
            if(!
    _root.brick)
            {
                
    _root.attachMovie("brick""brick"_root.getNextHighestDepth());
            }
        }
    }
    Key.addListener(KeysListener); 
    Otherwise:

    PHP Code:
    var KeysListener:Object = new Object();
    KeysListener.onKeyDown = function()
    {
        if(
    Key.isDown(Key.SPACE))
        {        
            
    _root.attachMovie("brick""brick"_root.getNextHighestDepth());
        }
    }
    Key.addListener(KeysListener); 
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

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