Use button on mc  to perfrom function on main timeline

I Was wondering how (or if it is posiible) to use a button I
have in a movie clip to perform a function on the main timeline.
Specifically, I want the button in the movie clip to gotoAndStop on
a frame in the main timeline. Any suggestions?

Hi,
Then you would target the movie clip.
So you would give the mc an instance name (like myClip_mc )
then just add this into your code ....
button1.onRelease = function() {
_root.myClip_mc.gotoAndStop(20);
This would tell the myClip_mc to stop on frame 20. Providing
the mc is located in the main timeline that is.
You can see from the code that we are going to the _root and
looking for the myClip_mc. If it is held within another mc (say
Holder_mc) then the code would change to
_root.Holder_mc.myClip_mc.gotoAndStop(20;
for cs3 (actionscript 3) it would be this
button1.addEventListener(MouseEvent.CLICK,clickHandler);
function clickHandler(event:MouseEvent):void{
_root.myClip_mc.gotoAndStop(20);
Hope this helps
Alan

Similar Messages

  • Call function in main timeline from class file

    Hi all, How can a function in main timeline be called from class file?

    Hi all, How can a function in main timeline be called from class file?
    You can, but you really shouldn't.
    Classes shouldn't "talk" to the outside directly.
    Use Event dispatching to get things done.
    "root" (i just threw up by just typing that word) should be avoided at all cost, especially in AS3.

  • In actionscript 3.0 how do i make a nested movie clip button go to a frame on the main timeline

    I am making a website based in flash actionscript 3.0 i have a button nested in its own movie clip, because I have the button expanding to be able to read it i have figured out the only way to do this is by creating it as a movie clipa nd inside the movie clip creating it as a button
    I added an event listener to the blog button by saying,
    blog.addEventListener(MouseEvent.ROLL_OVER,gotoblog);
    function gotoblog(evtobj:MouseEvent){
         gotoAndStop(2)
    this part of the code works it goes to the 2nd frame of the timeline it is in and stops wich is a blown up version of the origanal symbol
    i added on frame 2 a second command
    blog.addEventListener(MouseEvent.CLICK.gotoblogpage);
    function gotoblogpage(evtobj:MouseEvent){
    gotoAndStop("blogframe")
    trace("the blog button was clicked")
    i have named the symbol blog and have name the frame of where the blog page is going to be "blogframe" this line of code at the bottom is where i run into trouble the output window in Flash is saying "The blog button was clicked" just like i want it to. no errors are accouring why than is the playhead not going to frame "blogframe"? if the button is working when i click it the code is right i belive the problem here is it does not want the playhead to go to the frame i want it to. So i gues my question is, how can i make a button withing a movie clip interact with the main timeline?

    I have a similar problem if could please help me i'd really apreciate it!!
    So i have a looping animation of some thumbnails, the hierarchy goes like this
    Scene1(main timeline) -> imgBar(MC)->imgBarB(MC within the imgBar MC)
    My buttons symbols are in the last MC "imgBarB" where i have this code:
    ss1.addEventListener(MouseEvent.CLICK, OneButtonClicked);
      function OneButtonClicked(event:MouseEvent):void{
      MovieClip(root).gotoAndStop("ssbox1");
    I want to control the Btns in my "imgBarB" MC to play a labeled frame(named "ssbox1") on another MC on the main timeline,this other MC goes like this:
    Scene1(main timeline)->ssbox_mc(MC where my labeled frame is)

  • Ref functions on main timeline within MC

    Does any one know of a way I can call a function thats set up on the main timeline using AS in movie clip thats a child of the timeline?
    IE:
    I have a function called setName(); on the main timeline.... I also have a movieclip called contact_mc and I need to add EventListeners within the contact_mc that would some how call the setName(); function thats in its parent timeline... Any advise you can offer is apperciated!

    try:
    MovieClip(this.parent).setName();
    to reference the movieclip.  i'm not sure what events you want to trigger that function call.

  • XprtHelp: buttons in mc linked to labels on main timeline?

    I am making a very simple site with one timeline. This seems
    so simple but it isn't working: i created a mc that contains
    several buttons with over states. I placed the mc in my navigation
    menu with an invisible button to close it when user's mouse moves
    off. Where do I link the buttons in this movie clip to labels on
    the main timeline? It seems like I should select them in the mc,
    and use gotoandStop on that label. But when I click them in testing
    the movie, they don't work. I posted the (very) unfinished swf to
    my url:
    jkbeasley.com
    Can anyone help? I am sitting here alone with no experienced
    flashies to ask, and I hate when something so easy just will. not.
    come. to. me!!! THANKS!!!!!!!
    K

    Hi
    Seems straight forward enough - but it would be helpful if
    you could post the .fla as well.
    Thanx

  • Button in mc to display image on main timeline

    I have a movie clip (mc_menu) that sits on the main timeline. Inside mc_menu I have several buttons that display items inside the mc. I also need to display an image on the main timeline. I have converted the image to a movie clip (mc_01). I am using AS2.

    My knowledge with AS is essentially non-existant. I added the following code on an actions layer in the movie clip (mc_menu):
    _root.attachMovie(mc_forecaster2_test);
    I do not have any code in the main timeline for this interaction.
    I tried to place the mc_forecaster2_test on the main timeline stage, and put in code to make the visible false, and code in mc_menu to make the visible true, but so far, nothing has worked.

  • Buttons inside symbol to activate action on main timeline

    Hello I currently have a scrollable symbol placed on my stage. Inside that symbol are buttons which when clicked I want to use to hide and show different images on my stage. I can currently get the roll over images to work but when clicked they do nothing. Each button has an action of when clicked show"name of image" hide"all other images"
    Any help would be greatly appreciated.
    Thanks

    Hi, Tim Jaramillo
    I have an identical problem I hope you can help. I have been puzzling with the parameters and set-up of the piece of code for a “slider” Left/Right you published here 3 days ago.
    With the code available in Edge script panel, I try to address the main stage from de images in the “slider” symbol. When you click a thumbnail in the “slider” you see the right picture on the stage. Is it possible for you to explain how to do that?
    Thanks
    Santos
    File_sliderLR

  • Using cue points to trigger events on the main timeline...

    Hi--
    I have successfully placed an flv (video) file (progressive
    download) on the main timeline of my movie with controls to play
    and pause (Flash 8 Professional). So far, so good!
    NOW TWO PROBLEMS: Does anyone know how to set it up so that
    when a specific cue point is reached in the video, it triggers an
    action on the main timeline? In this case, once the video is over,
    I want the main timeline to gotoAndPlay frame 3. Specific script to
    do this would be great!
    The other action I'd like to happen is that when the video
    begins, it targets a scrolling text mc ("text") in the main
    timeline and tells it to gotoAndPlay frame 2.
    Any advice would be GREATLY appreciated!!! Many
    thanks!!!

    I usually start off solving problems with the livedocs, as I
    recommend for anyone. The following link will take you to the
    NetStream.onCuePoint handler. This is what you need.
    http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context= LiveDocs_Parts&file=00002561.html
    You can have this code on the main timeline. When the
    cuepoint is hit, it will invoke this event handler and inside is
    where your gotoAndPlay( ) should go.
    Your other question about the text will get activated by the
    same handler. Just have a conditional statement (if, switch, etc.)
    to differentiate between the two events. The text itself can be
    mask inside a movieclip.
    Does this help?

  • How to add button inside move clip and call it from main timeline?

    Hi,
    On the main timeline I  have a movie clip called clock_mc and playBtn
    playBtn is  placed in the center of clock_mc
    When you press playBtn clock_mc starts playing
    playBtn.addEventListener(MouseEvent.CLICK, playClock);
    function playClock(event:MouseEvent):void
        if (event.target == playBtn)
            clock_mc.play();
            playBtn.visible = false;
            trace ("play button was clicked");
    This is working fine for me.
    But I want to add replayBtn to the last frame of clock_mc and set up the function on main Timeline.
    Another words when the clock_mc rich last frame you see replayBtn.
    code example:
    replayBtn.addEventListener(MouseEvent.CLICK, playClock);
        if (event.target == replayBtn)
            clock_mc.play();
            replayBtn.visible = false;
            trace ("replay button was clicked");
    I've tryed to placed the replayBtn on the stage on the main timeline and I've set it up to replayBtn.visible = false;
    And then I add replayBtn.visible = true; to last AS frame of clock_mc but it wont work
    Even when I put the button physically to the last frame of clock_mc it will not work either.
    Please help

    I've solved the problem:-)
    I've set replayBtn.visible = false; on first frame of clock_mc
    and  replayBtn.visible = true; at the last frame
    and than as you sugested I'v add:
    clock_mc.replayBtn.addEventListener(MouseEvent.CLICK, replayClock);
    function replayClock(event:MouseEvent):void
            clock_mc.play();
            trace ("replay button was clicked");
    I couldn't see replayBtn at the firs stage because I have clockTween assosiated with clock:
    clockTween = new Tween(clock_mc, "x", Regular.easeOut, -469,438, .5, true);
    and I had replyBtn in the wrong place so when clock_mc was coming up on the stage replayBtn was on the left side of the stage :/
    Now I have to solve only one thing.
    Maybe you would have any suggestions please.
    I've set up stop(); in a first frame of clock_mc
    that when you see clock_mc sliding in it has to wait for playBtn to be clicked
    because I have two tween:
            clockTween = new Tween(clock_mc, "x", Regular.easeOut, -469,438, .5, true);
            playTween = new Tween(playBtn, "x", Regular.easeOut, -720,514, .5, true);
            playBtn.visible = true;
    so when you click on playBtn:
    function playClock(event:MouseEvent):void
        if (event.target == playBtn)
            clock_mc.play();
            playBtn.visible = false;
            trace ("play button was clicked");
    everythink is working fine except when I clik on replayBtn it play for I sec because there is stop(); on the first frame of clock_mc

  • How can i use Button in BEx  7.0

    Dear Folks,
    Could you help me please ..
    In BI 7.0, for BEx analyzer i see we can use button, combo box, analysis grid.
    If i have a requirement like this:
    1. I have sales report, where it has information about sales person.
    2. And i want to filter that report with the sales person that i choose from combo box.
    For that requirement, i tried to :
    1. I Create a query to Sales info-provider for displaying sales.
    2. I Create a query to either to MD Sales person / Sales info-provider in order to get Sales persons data.
    3. I assign point no 1 to Analysis Grid.
    4. I assign point no 2 to Combo box.
    My questions are:
    a. Is my techniques correct ??
    b. How can i use button to execute filter into the corresponding report ???
    c. Is there any tutorial regarding this ?? Could you share it to me please ..
    Really need your guidances..
    regards,
    Niel..

    Hi Niel,
    You can use the method you specified.
    In Bex Analyzer you have design mode where you can have the following items Button, Analysis Grid and Combo box.
    To work with the button you need to use the Command Wizard which consists of pre-defined functions, out of those select the one which suits your requirement and supply the parameters. As it is done thorugh a Wizard it would be easy to do.
    Also,
    The Button Name displays the name of the button, which is generated automatically and is unique. This name is used on the BEx Analyzer Design Toolbar menu to refer to a particular instance of the button.
    · Range u2013 Manipulate coordinates for a cell or cells in this field to move or resize the button.
    · Button Text - The text (caption) you want to display on the button. You can use this to describe the command the button executes.
    · Command Range (optional) - Specify a three-column range of cells in the worksheet that contains command parameters. In these cells, you provide the same parameters (Name, Index, and Value) as in the Static Parameters, but in the worksheet these can be variable, changing during
    navigation based on query results or on a value you manually specify.
    Button in Bex analyzer
    Regards,
    Neelesh Jain.

  • Why do we use open URL in default browser function? What are the uses of it?

    Why do we use "open URL in default browser" function?  What are the uses of it?

    kdm7 wrote:
    Okay.
    So can we keep a web button to access the www.ni.com ? So that web site opens only when button pressed?
    P.S  I,m a newbie.
    Yes, you can also, e.g. include a help file or manual as html and open that in the browser.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • In making a form, I've used buttons for user to select a state. Can I make it go to cities next?

    I don't know the correct terminology, so I don't think that I've posed my question very well.  Employees will be using the form that I'm trying to make, and I want for them to be able to select a city from a large number of cities, and for that city to ultimately show up on the form (not merely in the data that is output.)
    I thought that the clearest way for them to select a city would be for them to start by selecting the pertinent state first.  That would allow the list of cities in that state to be shorter and more manageable.  So I'd like for them to be able to select a state, and then by virtue of that selection, have a list of cities pop up.  I sort of achieved that by using buttons for the states, and then under "actions", I chose "open a file".  Then I set it up to open a file that contained the cities that are options,and set each city with a button. 
    The result is that it goes from my form to a second window, containing states and then to a third window, containing cities.  (Actually, there are multiple "city" windows because there's a list of cities for each state.)  But then I'd like for the city that they select to wind up being on my original form.  Is there an "action" that I can choose that will make that happen?
    Or is there a better way to accomplish what I'm trying to accomplish?  Maybe I'm just going about this all wrong(?) Any suggestions would be very much appreciated  Thank you!

    Yes, there is a much better way. I'd recommend using a combo box for the list of states. When the user selects a state, the list of associated cities would populate a second combo box, allowing the user to select a city. This type of functionality relies on JavaScript. If you are unfamiliar with with JavaScript in Acrobat, I'd suggest starting with the following article: http://acrobatusers.com/tutorials/2007/js_list_combo_livecycle/
    Ignore anything to do with LiveCycle Designer. If you get stuck, post again.

  • How to move a selected row data from one grid to another grid using button click handler in flex4

    hi friends,
    i am doing flex4 mxml web application,
    i am struck in this concept please help some one.
    i am using two seperated forms and each form having one data grid.
    In first datagrid i am having 5 rows and one button(outside the data grid with lable MOVE). when i am click a row from the datagrid and click the MOVE button means that row should disable from the present datagrid and that row will go and visible in  the second datagrid.
    i dont want drag and drop method, i want this process only using button click handler.
    how to do this?
    any suggession or snippet code are welcome.
    Thanks,
    B.venkatesan.

    Hi,
    You can get an idea from foolowing code and also from the link which i am providing.
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
    width="613" height="502" viewSourceURL="../files/DataGridExampleCinco.mxml">
    <mx:Script>
    <![CDATA[
    import mx.collections.ArrayCollection;
    import mx.binding.utils.BindingUtils;
    [Bindable]
    private var allGames:ArrayCollection;
    [Bindable]
    private var selectedGames:ArrayCollection;
    private function initDGAllGames():void
    allGames = new ArrayCollection();
    allGames.addItem({name: "World of Warcraft",
    creator: "Blizzard", publisher: "Blizzard"});
    allGames.addItem({name: "Halo",
    creator: "Bungie", publisher: "Microsoft"});
    allGames.addItem({name: "Gears of War",
    creator: "Epic", publisher: "Microsoft"});
    allGames.addItem({name: "City of Heroes",
    creator: "Cryptic Studios", publisher: "NCSoft"});
    allGames.addItem({name: "Doom",
    creator: "id Software", publisher: "id Software"});
    protected function button1_clickHandler(event:MouseEvent):void
    BindingUtils.bindProperty(dgSelectedGames,"dataProvider" ,dgAllGames ,"selectedItems");
    ]]>
    </mx:Script>
    <mx:Label x="11" y="67" text="All our data"/>
    <mx:Label x="10" y="353" text="Selected Data"/>
    <mx:Form x="144" y="10" height="277">
    <mx:DataGrid id="dgAllGames" width="417" height="173"
    creationComplete="{initDGAllGames()}" dataProvider="{allGames}" editable="false">
    <mx:columns>
    <mx:DataGridColumn headerText="Game Name" dataField="name" width="115"/>
    <mx:DataGridColumn headerText="Creator" dataField="creator"/>
    <mx:DataGridColumn headerText="Publisher" dataField="publisher"/>
    </mx:columns>
    </mx:DataGrid>
    <mx:FormItem label="Label">
    <mx:Button label="Move" click="button1_clickHandler(event)"/>
    </mx:FormItem>
    </mx:Form>
    <mx:Form x="120" y="333">
    <mx:DataGrid id="dgSelectedGames" width="417" height="110" >
    <mx:columns>
    <mx:DataGridColumn headerText="Game Name" dataField="name" width="115"/>
    <mx:DataGridColumn headerText="Creator" dataField="creator"/>
    <mx:DataGridColumn headerText="Publisher" dataField="publisher"/>
    </mx:columns>
    </mx:DataGrid>
    </mx:Form>
    </mx:Application>
    Link:
    http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/ae9bee8d-e2ac-43 c5-9b6d-c799d4abb2a3/
    Thanks and Regards,
    Vibhuti Gosavi | [email protected] | www.infocepts.com

  • After loading FF4 the back/forth buttons are visible but not functional. Have tried to reset tool bar etc. no luck. fix please

    After upgrading to the new version everything seems to work well except my back/forth button on the browser are visible but grayed out and not functional. I have tried all of the suggestions in help and am unable to bring them to life. Very frustrating to use a browser with out these functions. I run 4 websites and it is maddening to have to keep reloading the sites just for simple work.
    I have to have these working or will be forced to use another browser. I liked the old FF much better. I can not tolerate this much longer.

    I notice from your system specs that you're running a very old version of Flash. Could you try updating to the latest one which is 10.2.159.1 It also contains a patch to fix a recently discovered [http://www.h-online.com/security/news/item/Adobe-releases-security-update-for-Flash-Player-1228930.html Zero Day exploit]. You can get it from here: http://get.adobe.com/flashplayer/
    Have you experienced any unusual events watching Flash videos lately? It's possible that you may have been a victim of just such an attack. It might be worth doing a malware scan using this well-known scanner from http://www.malwarebytes.org/ The free version is more than adequate to eliminate any current threats.

  • Removing Splash Screen using button in Movieclip

    Hi
    I have created a shooting game and I am struggling to create a splash screen at the beginning informing the user of
    the controls with a button to start the game, which removes the splash screen. I am trying to add the splash screen in the main timeline
    using addChild event. I can get the splash screen to appear on the game and remove it when the playgame button is pressed, but this
    prevents all the other event listeners so I am not able to fire or move the ship.
    In the splash screen I have the code :
    Play_btn.addEventListener(MouseEvent.CLICK,playgame)
    function playgame(e:Event):void
    Play_btn.removeEventListener(MouseEvent.CLICK,playgame)
    parent.removeChild(this);
    and in the main timeline I have :
    addChild(splashscreen);
    Can anyone give me some guidance, thanks for reading this

    Hi
    thanks for taking the time, I don't know how to upload the fla so here is my code.
    The code in the splashscreen MovieClip, which has a button called Play_btn is :
    Play_btn.addEventListener(MouseEvent.CLICK,playgame);
    function playgame(e:Event):void
    parent.removeChild(this);
    Play_btn.removeEventListener(MouseEvent.CLICK,playgame)
    and the code in the main timeline is :
    //import some important flash libraries.
    import flash.events.KeyboardEvent;
    import flash.events.Event;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.sampler.Sample;
    var score:Number=0;
    var countCollisions:Number =0;
    var astArray:Array = new Array();
    var enemyshipArray = new Array();
    var enemybulletArray = new Array();
    var explosionArray = new Array()
    var speed:Number = 10;
    var key_left:Boolean = false;
    var key_right:Boolean = false;
    var key_up:Boolean = false;
    var key_down:Boolean = false;
    var key_space:Boolean = false;
    var shootLimiter:Number=0;
    var splashscreen:MovieClip = new Splash();
    //Play_btn.addEventListener(MouseEvent.CLICK,playgame);
    splashscreen.x = 0;
    splashscreen.y = 0;
    addChild(splashscreen);
    //removeChild(splashscreen);
    background.addEventListener(Event.ENTER_FRAME,backgroundmove);
    function backgroundmove(e:Event):void
    background.x -= 1;
    if(background.x < -200)
    background.x = 749.95;
    this is how you can comment over a number
    of different lines
    var timer:Timer = new Timer(1000, 10);
    timer.addEventListener(TimerEvent.TIMER, AddAsteroid);
    timer.start();
    var timerenemyship:Timer = new Timer(2000, 10);
    timerenemyship.addEventListener(TimerEvent.TIMER, Addenemyship);
    timerenemyship.start();
    stage.addEventListener(KeyboardEvent.KEY_DOWN,KeyDown);
    stage.addEventListener(KeyboardEvent.KEY_UP,KeyUp);
    var ship:MovieClip = new Ship()
    var enemyship:MovieClip = new EnemyShip()
    addChild(ship);
    function Addenemyship(e:TimerEvent):void
    var enemybullettimer:Timer = new Timer(2000, 10);
    enemybullettimer.addEventListener(TimerEvent.TIMER, Addenemybullet);
    var enemyship:MovieClip = new EnemyShip();   
    enemyship.x = 800;
    enemyship.y = Math.round(Math.random()*400);
    enemyshipArray.push(enemyship); 
    addChild(enemyship);
    enemybullettimer.start();
    function Addenemybullet(e:TimerEvent):void
    var enemybullet:MovieClip = new EnemyBullet();
    enemybullet.x = enemyship.x+50;
    enemybullet.y = enemyship.y+50;
    enemybulletArray.push(enemybullet);  
    addChild(enemybullet);
    enemybullet.addEventListener(Event.ENTER_FRAME,moveenemybullet);
    function moveenemybullet(e:Event):void
    enemybullet.x -=30;
        if(enemybullet.hitTestObject(ship))
       removeChild(ship);
    enemyship.addEventListener(Event.ENTER_FRAME,enemyshipmove);
    function enemyshipmove(e:Event):void
    enemyship.x -=10;
    for(var i=0; i<enemyshipArray.length; i++)
         if(enemyshipArray[i].hitTestObject(ship))
    // EXPLOSION
    var explosion:MovieClip = new Explosion();
    addChild(explosion);
    explosion.x =ship.x;
    explosion.y = ship.y;
    explosionArray.push(explosion);
    for (var l:int=0; l<explosionArray.length; l++)
    if (explosionArray[l].currentFrame == 10)
    removeChild(explosionArray[l]);
    explosionArray.splice(l,1);
    // END OF EXPLOSION  
            MovieClip(enemyshipArray[i]).removeEventListener(Event.ENTER_FRAME, enemyshipmove);
            removeChild(enemyshipArray[i]);
            enemyshipArray.splice(i, 1);
            countCollisions++;
             if(countCollisions >= 2)
             ship.gotoAndPlay(87);
       else
             ship.gotoAndPlay(6);
    function AddAsteroid(e:TimerEvent):void
    var asteroid:MovieClip = new Asteroid();   
    asteroid.x = 800;
    asteroid.y = Math.round(Math.random()*700);
    astArray.push(asteroid);  
    addChild(asteroid);
    asteroid.addEventListener(Event.ENTER_FRAME,asteroidmove);   
    function asteroidmove(e:Event):void
    asteroid.x--
    for(var i=0; i<astArray.length; i++)
         if(astArray[i].hitTestObject(ship))
            MovieClip(astArray[i]).removeEventListener(Event.ENTER_FRAME, asteroidmove);
            removeChild(astArray[i]);
            astArray.splice(i, 1);
            countCollisions++;
             if(countCollisions >= 4)
              ship.gotoAndPlay(87);
       //removeChild(ship);
       else
             ship.gotoAndPlay(6);
    addEventListener(Event.ENTER_FRAME,Main);
    function Main(event:Event)
    CheckKeys();
    function KeyDown(event:KeyboardEvent)
    if(event.keyCode == 37){  //checks if left arrowkey is pressed.
      key_left = true;
    if(event.keyCode == 39){  //checks if right arrowkey is pressed.
      key_right = true;
    if(event.keyCode == 38){  //checks if up arrowkey is pressed.
      key_up = true;
    if(event.keyCode == 40){  //checks if down arrowkey is pressed.
      key_down = true;
    if(event.keyCode == 32){  //checks if down arrowkey is pressed.
      key_space = true;
    function KeyUp(event:KeyboardEvent){
    if(event.keyCode == 37){  //checks if left arrowkey is released.
      key_left = false;
    if(event.keyCode == 39){  //checks if right arrowkey is released.
      key_right = false;
    if(event.keyCode == 38){  //checks if up arrowkey is released.
      key_up = false;
    if(event.keyCode == 40){  //checks if down arrowkey is released.
      key_down = false;
    if(event.keyCode == 32){  //checks if down arrowkey is released.
      key_space = false;
    function CheckKeys()
    shootLimiter += 1;
    if(key_left)
      setDirection(1);
      ship.x -= 5;
    if(key_right)
      setDirection(0);
      ship.x += 5;
    if(key_up){
      ship.y -= 5;
    if(key_down){
      ship.y += 5;
    if((key_space) && (shootLimiter > 8))
    shootLimiter = 0;
    var b = new Bullet();
    addChild(b);
    // ADD SOUND
    var bulletsound:Sound=new SoundEnemyShot()
        bulletsound.play();
    // END SOUND
    b.x = ship.x + 50;
    b.y = ship.y + 3;
    addEventListener(Event.ENTER_FRAME,moveBullet);
    function moveBullet(e:Event):void
    b.x +=10;
      if(b.x > 600)
       if(contains(b))
       removeChild(b);
              removeEventListener(Event.ENTER_FRAME,moveBullet);
      for(var i=0; i<astArray.length; i++)
       if(astArray[i].hitTestObject(b))
       removeChild(b);
       removeChild(astArray[i]);
          score +=10;
       score_txt.text = score.toString() ;
       removeEventListener(Event.ENTER_FRAME,moveBullet);
    for(var i=0; i<enemyshipArray.length; i++)
      if(enemyshipArray[i].hitTestObject(b))
      removeChild(b);
      removeChild(enemyshipArray[i]);
            enemyshipArray.splice(i, 1);
      MovieClip(enemyshipArray[i]).removeEventListener(Event.ENTER_FRAME, moveBullet);
    function setDirection(param) {
    if (param == 0) {
      ship.scaleX = 1;
    } else {
      ship.scaleX = -1;

Maybe you are looking for