Buttons in ActionScript 3 ?!?!?!

hi...
I'm trying to make a sound controller in actionscript 3. I
used to do this nicely in actionscript 2, but know it seems that
nothing works as in "the old days"...
I created a button and tried to add actionscript to it but it
doesn't let me :-(
How can i apply code to a button on flash CS3 to start and
stop a specific sound?

ActionScript 3.0 was designed for advanced Object-Oriented
programmers. Even though this approach is a lot more powerful, it
requires a lot of knowledge and re-learning. Like for example that
every on() event is not only deprecated in this version but
completely removed. So, as the same documentation says. If your
project is not a giant monster, there is no need to learn this
programming approach, which will take you a considerable time. You
can still export as Flash Player 9 to use its improvements but
select ActionScript 2.0 as the ActionScript version on the publish
settings panel.
Take into account that the object structure in ActionScript
3.0 was completely redesigned. So every proccess, from a sinple
event to movie clip creation has changed radically.

Similar Messages

  • Animating a button with actionScript

    I'm fairly stumped on this one - but probably quite simple to fix.
    I need to animate the scale of a button with actionScript 2.0. I've inherited a project that was done with actionScript 2.0 and have decided to stay with this generation rather than rewrite the whole project. Anyway - I've created a sound object, it plays audio from the library and 3 seconds after it starts playing, I want to animate the "next" button and make it pulse to attract the users attention.
    Doing this by putting the button in a movie clip is not working as I am losing it's button states and besides it's probably far more tighter to program it.
    When the user rolls over the button it stops pulsing but still retains it's up, over and down states.
    Any easy answer?

    Thanks for your help Ned.
    I ended up making an advanced button with movie clips and using programming for all the states.
    Movies are so much easier to control than buttons.
    But you have raised something I had overlooked...setTimeout( )
    I was using setInterval( ) and then doing clearInterval( ) within the function so it would only loop once, which of course was problematic if the user beat the 'clearInterval' code by clicking on the button too early.
    Actually used setInterval( ) to delay all sound on the project - now going to re-program all that.
    Thanks

  • Fullscreen button in Actionscript 2

    Hi everyone.  I hope someone can help me with this.  I'm having some problems making a fullscreen button in Actionscript 2 that works in a swf file.  You see, this document I'm making isn't going to be going on the web.  It's just going to be shown on a computer at company events.  However, I need a button that makes the document fullscreen, and none of the codes I've tried have seemed to work in the swf.  Here is the current code I'm working with:
    //Don't scale the movie when the stage size changes
    Stage.scaleMode="noScale";
    //Align the stage to the top left
    Stage.align = "TL";
    //Function to toggle between fullscreen and normal size
    //the toggle fullscreen button calls this function when pressed
    function toggleFullScreen(){
        //if normal size, go to fullscreen, else go to normal size
        if(Stage["displayState"]=="normal"){
            Stage["displayState"]="fullScreen";
        }else{
            Stage["displayState"]="normal";
    //Create a listener for each time the Stage is resized
    var resizeListener:Object = new Object();
    //Called each time the stage is resized
    resizeListener.onResize = function () {
        //Move the button to the center of the screen
        toggleFullScreenButton._x=Stage.width/2;
        toggleFullScreenButton._y=Stage.height/2;
    //Add the listener to Stage
    Stage.addListener(resizeListener);

    I got this compiler error: 
    Scene=Scene 1, layer=Layer 1, frame=1, Line 20
    Unexpected '}' encountered
    And yes, the instance name on the button is toggleFullScreenButton.  Here is all the AS with your code that I just tried.
    //Don't scale the movie when the stage size changes
    Stage.scaleMode="noScale";
    //Align the stage to the top left
    Stage.align = "TL";
    //Function to toggle between fullscreen and normal size
    //the toggle fullscreen button calls this function when pressed
    function toggleFullScreen(){
        //if normal size, go to fullscreen, else go to normal size
        // add a trace which appears in the output panel when you "TEST" your movie (e.g. CTRL+ENTER inside Flash)
         trace("Toggle full screen button was pressed");
         if (Stage.displayState == "normal") { Stage.displayState = "fullscreen"; }
         else { Stage.displayState = "normal"; }
    //Create a listener for each time the Stage is resized
    var resizeListener:Object = new Object();
    //Called each time the stage is resized
    resizeListener.onResize = function () {
        //Move the button to the center of the screen
        toggleFullScreenButton._x=Stage.width/2;
        toggleFullScreenButton._y=Stage.height/2;
    //Add the listener to Stage
    Stage.addListener(resizeListener);
    And on the button itself is this code:
    on(press){
        toggleFullScreen();

  • Mute and unmute button is actionscript 3.0

    Hi,
    I am wondering how to make a mute and unmute button is actionscript 3.0.  I did it before in actionscript 2.0 but not in 3.0.
    Here is my actionscript 2.0 code.
    var sound = 1;
    var slashMC = _root.attachMovie("slash","slash01",99);
    slash01._visible = false;
    slashMC._y = btn._y;
    slashMC._x = btn._x;
    var s:Sound = new Sound();
    s.attachSound("Gravy");
    s.start(1,999);
    btn.onPress = function(){
    if(sound==1){
      s.stop();
      slash01._visible = true;
      sound = 0;
    else if(sound==0){
      sound = 1;
      slash01._visible = false;
      s.start(1,999);
    Thanks

    Try this:
        import flash.display.MovieClip;
        import flash.events.*;
        import flash.media.*;
        import flash.net.URLRequest;
            var isPlaying:Boolean = false;
            var snd:Sound = new Sound();
            var channel:SoundChannel = new SoundChannel();
            var pos:Number = 0;
            var soundVolume:Number = 1;
                snd.load(new URLRequest("something.mp3"));
                btn_Stop.addEventListener(MouseEvent.CLICK, stopMusic);
                btn_Stop.buttonMode = true;
                btn_Play.addEventListener(MouseEvent.CLICK, playMusic);
                btn_Play.buttonMode = true;
             function stopMusic(evt:Event):void
                channel.stop();
                pos = 0;
                isPlaying = false;
             function playMusic(evt:Event):void
                if(!isPlaying)
                    channel = snd.play(pos);
                    btn_Play.visible = false;
                    btn_Pause.visible = true;
                    isPlaying = true;

  • How to set an icon of a Button in ActionScript ?

    A need to create at runtime some buttons and set their icons.
    I found a problem to do that in ActionScript. In MXML is easy
    to set the icon just use a syntax like this: <mx:Button
    label="some text" icon="images/ok.png"/>
    But in ActionScript how I can set the icon ?
    I need to create the icon by a path passed as a parameter.
    Example:
    The user want to create a button with a label and an icon so
    call a method like this (that return and instance of Button):
    createButton("Update","images/update.png");
    Thank at all for the help.
    Marco

    supahsain08 wrote:
    Well i did this
    Triangle.setLocation(50, 100);
    (where Triangle is a buton)
    it doesn't do anything, stays at the same placeIt's all about context here and there are still many unknowns here that can effect your result and that you have not told us or shown us. My suggestion to you is to consider posting an SSCCE (Short, Self Contained, Correct (Compilable), Example, a condensed program similar to your current program in that it demonstrates the problem at hand, but is the smallest bit of code that still compiles and has no extra code that's not relevant to your problem. For more info on SSCCEs please look here:
    [http://homepage1.nifty.com/algafield/sscce.html|http://homepage1.nifty.com/algafield/sscce.html]
    Also, when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, you can will need to paste already formatted code into the forum, highlight this code, and then press the "code" button at the top of the forum Message editor prior to posting the message. You may want to click on the Preview tab to make sure that your code is formatted correctly. Another way is to place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:
    &#91;code]
      // your code block goes here.
      // note the differences between the tag at the top vs the bottom.
    &#91;/code]or
    {&#99;ode}
      // your code block goes here.
      // note here that the tags are the same.
    {&#99;ode}good luck, pete

  • Help with Buttons in Actionscript 2

    Help!! I am creating a Flash movie with 5 scenes. I have
    buttons for each that I have added actionscript to, but they still
    do not work. I am not getting any error messages. I am using
    actionscript 2 and have gone step by step. here is what i have :
    on (release) {
    gotoAndStop("main", 1);
    on (release) {
    gotoAndStop("blackboard", 1);
    etc for the rest of the buttons. Any help would save me much
    stress as I am trying to finish a project for school!!! thanks
    ah

    Try adding _root. before the gotoAndStop command. If you have
    the code on the buttons that is.

  • Enabling and disabling buttons in actionscript

    in flex i love using the enabled option for buttons (so when the user has not yet selected something in a datagrid or if a variable in the app is not properly set the button will not be enabled and will be grayed out... but once the condition is true the button automatically becomes enabled) like this:
    <mx:Button 
    label="Save Changes" icon="@Embed(source='images/disk.png')" click="saveData();"enabled="
    {firstID != 0 &amp;&amp; changesMade == true}"/>
    i have a control bar that has buttons but if the user is an Admin they have additional buttons (which i created using actionscript in an initApp() function once the app initializes like this):
     if (adminList.indexOf(Application.application.parameters.emplid) != -1){ 
    var but:Button = new Button();but.label =
    "Delete Account";but.addEventListener(
    "click",confirm);but.setStyle(
    "icon", deleteIcon);  
    this.toolbar.addChild(but);}
    how can i code the enabled function that i use i mxml in actionscript in the code above?

    oops i just realized i forgot the return type.
    this is helpful when the button is first created and the app is first initialized... but i need this button to automatically become enabled if the user does something (like click on a datagrid) and automatically disabled when the user clicks off of the datagrid (or some action that would enable/disable the button).
    public function loadAdmins(returnedEvent:ResultEvent):void {adminList = returnedEvent.result[0].DEPT_LIST;
    if (adminList.indexOf(Application.application.parameters.emplid) != -1){ 
    var delBtn:Button = new Button();delBtn.label =
    "Delete Account";delBtn.addEventListener(
    "click",confirm);delBtn.setStyle(
    "icon", deleteIcon);delBtn.enabled=delBtnEnabled();
    this.toolbar.addChild(delBtn);}
    public function delBtnEnabled():Boolean{ 
    var returnVal:Boolean; 
    if (firstID != 0){returnVal =
    true;}
    else{returnVal =
    false;}
    return returnVal;}

  • Trying to add a paypal button in actionscript 2.0?

    So the company I work for wants to add a paypal button to the website (not a buynow or a shopping cart). We received the html code but the flash doesn't accept it. So I've been creating an actionscript for it without luck.
    I've tried:
    on(release){getURL("https://www.paypal/cart/add=1&business= EMAIL HERE");
    cmd="_cart";
    business="EMAIL HERE";
    value="ACCOUNT CODE"
    I received no errors and it goes to paypal but doesn't link the customer with the account.
    So I tried this:
    on (release) {getURL(form action)=("https://www.paypal.com/cgi-bin/webscr",method="post");}
    on (release) {var link:String=("https://www.paypal.com/cgi-bin/webscr");}
    on (release) {var cmd:String="_x-sclick";}
    var encrypted:String="<form action= {getURL(form action)=("https://www.paypal.com/cgi-bin/webscr",method="post");}
    input type="hidden" name="cmd" value="_s-xclick
    input type="hidden" name="hosted_button_id" value="CZ6JUTK9ND9QU"
    input type="image" src=("https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!");
    img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"
    /form
    var paypal:LoadVars=new LoadVars();
    function sumbit (){
    paypal.cmd=cmd;
    paypal.encrypted=encrypted;
    paypal.send (link,"_blank","POST")
    But receive 1 error and it doesn't do much of anything.
    I need help

    Zoom Search Engine software
    http://www.wrensoft.com/zoom/index.html
    Free Find
    http://www.freefind.com/
    Google Site Search -
    http://www.google.com/sitesearch/
    Web Assist DW Tools for Google (free)
    http://www.webassist.com/free-downloads/dreamweaver-extensions/dreamweaver-tools-for-googl e/
    Nancy O.

  • How  to align buttons using ActionScript in Flex

    Hi all, I'm pretty new to Flex and ActionScript but
    I’ve created an myAddForm() function in an actionscript class
    but I can't align the buttons - I’ve been looking at using a
    buttonbar but can't figure out how to convert the code in to
    actionscript from the mxml examples. any advice what to use...
    function below.. This works but with the button on top of one
    another.. Any help is greatly appreciated

    Ooops - I indeed mean ActionScript.
    In any case, what is the difference between ExtensionBuilder and "FlashBuilder + CSIDE libs"? Is ExtensionBuilder that thing that you have to be a Partner for and nobody alive today has managed to reach the person at Adobe who adds you to the program?
    Apropo the upcoming holoday, I understand that successfully contacting Adobe about joining the CS5 SDK partner program is sort of like virgin birth - the last time it happened was 2010 years ago and nobody alive today has ever seen it happen...
    I THINK I am using FlashBuilder plus the CS5 SDK Framework. So how do I catch events that way, since I don't see the CS5 options in the project's properties dialog.
    mlavie

  • Buttons and ActionScript Code

    Hi everyone just signed up to this forum today, really need help, would appreciate your help.
    Basically I have created 5 buttons on one single layer. I am now trying to link each button to a website, but to no success as of yet.
    I realised that maybe in order to make it easier for myself I need to put each button in its own layer and insert the following actionscript code I've inserted for one of my buttons:
    stop()
    home_btn.addEventListener(MouseEvent.CLICK, mouseClick);
    function mouseClick(event:MouseEvent):void
    var request = new URLRequest("http://www.sign-technologies.net/");
    navigateToURL(request,"_blank");
    This code links my first button "home_btn" to my site, which is still underconstruction. When I run it in flash it works, but when I click the button in the actual web browser it will not go to the webpage, so I'm stuck.
    Another question: For convience sake is there a way I can have all the buttons in one layer, but insert code that can seperate one button from the other? Anyone have that code?

    You can place all of your buttons in one layer and all of your code preferably in another layer.  What you will need to do is have differently named functions for each button.  You can not name them all "mouseClick"... I'll suggest you name the function in relation to the button, as in....
    home_btn.addEventListener(MouseEvent.CLICK, homeClick);
    function homeClick(event:MouseEvent):void
         var request = new URLRequest("http://www.sign-technologies.net/");
         navigateToURL(request,"_blank");
    As far as the file not working when testing in a browser, it should.  There is nothing wrong with the code.
    There are other ways of coding where you can have the same function shared by all the buttons, but that might be a better lesson for another day.

  • SWF Play Button Template ActionScript

    Thank you in advance for any help or direction!
    My cleint needs a file for the web that is in SWF format and
    in a player. We are using Sorenson Squeeze to create the file as
    well as using a Sorenson player template. My hang up is that they
    would like the PLAY button to appear right away and the default of
    the player is to wait until the file is fully downloaded.
    Is there an actionscript that will allow me to have the PLAY
    button available to start the movie before the file is completely
    downloaded? Or, an option to edit the player in Flash along the
    same lines and re-export the player?

    If the annotation isn't activated, you are printing the JPEG poster image instead - which doesn't have transparency. By default, poster images created from the media will have the play icon burned in, just choose your own image.

  • Need help with Buttons with ActionScript

    I am trying to create a button that will go to a different
    scene in my flash project using
    on (press) { gotoAndPlay(about,1);
    I have done this several times before, however, for some
    reason every time I try to put actions on my buttons it says that
    actions can't be applied to it. I have even tried switching them to
    movie clips. I can't figure out what is wrong.
    Any help would be greatly appreciated!
    Thanks

    Thanks for you help!!!! That worked!

  • Making a loaded external image into a button in Actionscript

    My name is Steve Oatman I am a student at
    AIO for a Web Design Diploma
    class: Interactive Telecommunications IMD412 XA
    Professors to bussy!
    I have a flash web site that I am putting together. I am using AS to load some images from an external source. These images are being loaded into a movieclip. These images need to become buttons once they are loaded. The images will link to the particular menu category pages beef, chicken, etc.
    The images are loading fine they just are not responding like a button or link.
    I am getting two error referencing the buttonMode and usehandCursor. Below is just one image that I am working on till I get it to work.
    I am getting these two Compiler error code:
    1119: Access of possibly undefined property buttonMode through a reference with static type flash.display:Loader.
    1119: Access of possibly undefined property useHandCursor through a reference with static type flash.display:Loader.
    This is what I have.
    var myLoader01:Loader = new Loader();
    myLoader01.load(new URLRequest("entrees_images/beef/beef01.gif"));
    addChild(myLoader01);
    myLoader01.x = -269;
    myLoader01.y = -164;
    myLoader01.buttonMode = true;
    myLoader01.useHandCursor = true;
    myLoader01.addEventListener(MouseEvent.CLICK, beefClick);
    function beefClick(event:MouseEvent):void{
    gotoAndStop("beef");
    From me searching online I thought the
    name.buttonMode = true;
    turned the element into a button!
    I have included the fla file. This is in the menuItems_mc which is located in the pageContent_mc frame 40 layer page Image or of course the library.
    I know this is a little in depth sorry and any help would be greatly appreciated.
    Steve
    713/742-3325

    Try something along the following lines:
    var myLoader01:Loader = new Loader();
    function addIt(evt:Event):void{
       var aBtn:MovieClip = new MovieClip();
       aBtn.x = -269;
       aBtn.y = -164;
       aBtn.buttonMode = true;
       addChild(aBtn);
       aBtn.addChild(myLoader01);
       aBtn.addEventListener(MouseEvent.CLICK, beefClick);
    myLoader01.contentLoaderInfo.addEventListener(Event.COMPLETE, addIt);
    myLoader01.load(new URLRequest("entrees_images/beef/beef01.gif"));
    function beefClick(event:MouseEvent):void{
       gotoAndStop("beef");

  • Making a button in actionscript 3.0 HELPPP!!!

    ok so in my animation class i used one that always worked, but i can't remember it and school is over! The button made it so that you stayed on the scene until the button was clicked, when the button was clicked it took you to whatever scene i put in the actions.  I tried this coding but to no avail! >
    btn_1.addEventListener(MouseEvent.Mouse_UP,mouseUpHandler);
    function mouseUpHandler(event:MouseEvent):void {
    gotoAndPlay (1,"Scene 2");
    I know i need a stop(): up top but other than that i don't know what to do! I know the code i useddidn't have
    btn_1.addEventListener(MouseEvent.Mouse_UP,mouseUpHandler);
    OR
    function mouseUpHandler(event:MouseEvent):void {
    I know this isn't very descriptive, but if anybody has better coding it'd be a great help! (I'm working on a short movie and I don't want it to loop play!)

    Put a trace call in your mouseUpHandler function to see if the button is calling the function.  If you don't know what a trace call is, it's just a way of getting feedback while you test your program and it displays whatever you tell it to in the output panel....
    function mouseUpHandler(event:MouseEvent):void {
        trace("the function is called");
        gotoAndPlay (1,"Scene 2");
    If you happen to be getting any error messages you need to include them in your posting.
    If all the above yields nothing unexpected, then what do you have in frame 1 of Scene 2?

  • Exit button for ActionScript 3.0 class

    Hi
    I want to exit my swf or exe file using the exit button, I try this code but its not working
    package  {
                        import flash.display.SimpleButton;
                        import flash.display.MovieClip;
                        import flash.events.MouseEvent;
                        import flash.system.fscommand;
                        public class b_exit extends SimpleButton {
                        public function b_exit() {
                                  this.addEventListener(MouseEvent.CLICK,clickF);
                        private function clickF(e:MouseEvent):void{
                                  fscommand("quit");

    This one work when you hit the back or home button:
    import flash.system.Capabilities;
    import flash.desktop.SystemIdleMode;
    if (Capabilities.cpuArchitecture == "ARM")
    NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true);
    NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate, false, 0, true);
    NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);
    //==================================================================
    public function handleActivate(event:Event):void
    NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
    //==================================================================
    public function handleDeactivate(event:Event):void
    NativeApplication.nativeApplication.exit();
    //==================================================================
    public function handleKeys(event:KeyboardEvent):void
    if (event.keyCode == Keyboard.BACK)
    NativeApplication.nativeApplication.exit();

Maybe you are looking for

  • Exchange Rate Difference in PO with cost center assignment

    Hi All, In case of exchange rate difference in a PO with a cost center assignment the system Do not post the difference in the exchange rate difference account (maintained under transaction type - KDM - in T-code OBYC). However if the PO is a normal

  • Warning - LR2.7 and Elements 7 are no longer compatible

    Tom Hogarty has confirmed that Adobe are not providing ACR5.7 for Elements 7 http://forums.adobe.com/message/2757553#2757553 hence losing compatibility between the 2 products Ian

  • How can I get iCloud inbox to receive incoming mail

    I am unable to receive incoming messages in iCloud inbox on iPad 2. I followed all troubleshooting steps Including adding and deleting iCloud account.

  • J1inchln Chanllan

    Dear All, We have encounter a issue.We are 6.0, when we run J1INCHLN for Section Code 195,we are not geeting the break up of the Tax amount(though the document has been posted) on saving the same. But other section codes we are able to get the break

  • Album art not showing all the time

    Is there a way to keep the album artwork to consistently show up? It seems like everytime I go into the music section, there's artwork missing...even though it's all there in iTunes and I sync it every time.