Start/Stop button in AS3

Hi all i have a problem. I'm developing an iOS app, a scoreboard. I added a start button, a stop button and a reset button but there isn't enaugh space for the buttons. So i decided to create a Start/Stop Button.
Pratically, the button displays starts, i pass the mouse over and the timer start. Then the button displays Stop, i pass the mouse and the timer stop, then it displays another time start ecc.
How to do this?
import flash.events.*;
var ScoreHome:Number = 0;
HomeScore.text = scoreFormat(ScoreHome);
var ScoreGuest:Number = 0;
GuestScore.text = scoreFormat(ScoreHome);
var timePattern:RegExp = /\d\d\:\d\d(?=\s)/;
var secondPattern:RegExp = /(?<=\:)\d\d(?=\s)/;
var time:Date = new Date();
var timer2:Timer = new Timer(1000, 24);
timer2.addEventListener(TimerEvent.TIMER, countdownpossesso);
//timer2.start();
var timer:Timer = new Timer(1000, 360);
timer.addEventListener(TimerEvent.TIMER, countdown);
//timer.start();
ButtonplusHome.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandleradd);
ButtonminusHome.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerminus);
StartSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerSS);
StopSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerStS);
ResetSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerRS);
Reset24.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler24);
ButtonplusGuest.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandleraddg);
ButtonminusGuest.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerminusg);
Seconds.text = "06:00";
Possesso.text = "24";
function countdown(e:TimerEvent):void
     time.time = (timer.repeatCount - timer.currentCount) * 1000;
     Seconds.text = time.toString().match(timePattern)[0];
     if (timer.repeatCount == timer.currentCount) {
          playSound(Event);
function countdownpossesso(e:TimerEvent):void
     time.time = (timer2.repeatCount - timer2.currentCount) * 1000;
     Possesso.text = time.toString().match(secondPattern)[0];
     if (timer2.repeatCount == timer2.currentCount) {
          playSound(Event);
function playSound(Event):void {
   mySound.play()
   timer.stop()
function scoreFormat(value:Number):String
     return String(value <= 9 ? "0" + value : value);
function fl_MouseOverHandleradd(e:MouseEvent):void
     ScoreHome++;
     HomeScore.text = scoreFormat(ScoreHome);
function fl_MouseOverHandlerminus(e:MouseEvent):void
     ScoreHome--;
     HomeScore.text = scoreFormat(ScoreHome);
function fl_MouseOverHandlerSS(e:MouseEvent):void
     timer.start()
     timer2.start();
function fl_MouseOverHandlerStS(e:MouseEvent):void
     timer.stop()
     timer2.stop();
function fl_MouseOverHandlerRS(e:MouseEvent):void
     timer.reset()
     timer2.reset()
     timer.start()
     timer2.start()
     timer.stop()
     timer2.stop()
     Seconds.text = "06:00";
     Possesso.text = "24";
function fl_MouseOverHandleraddg(e:MouseEvent):void
     ScoreGuest++;
     GuestScore.text = scoreFormat(ScoreGuest);
function fl_MouseOverHandlerminusg(e:MouseEvent):void
     ScoreGuest--;
     GuestScore.text = scoreFormat(ScoreGuest);
function fl_MouseOverHandler24(e:MouseEvent):void
     timer2.reset()
     timer2.start()
     Possesso.text = "24";
var mySound:Sound = new Buzzer();

use a movieclip button:
import flash.events.*;
var ScoreHome:Number = 0;
HomeScore.text = scoreFormat(ScoreHome);
var ScoreGuest:Number = 0;
GuestScore.text = scoreFormat(ScoreHome);
var timePattern:RegExp = /\d\d\:\d\d(?=\s)/;
var secondPattern:RegExp = /(?<=\:)\d\d(?=\s)/;
var time:Date = new Date();
var timer2:Timer = new Timer(1000, 24);
timer2.addEventListener(TimerEvent.TIMER, countdownpossesso);
//timer2.start();
var timer:Timer = new Timer(1000, 360);
timer.addEventListener(TimerEvent.TIMER, countdown);
//timer.start();
startstop.addEventListener(MouseEvent.MOUSE_OVER,stopstartF);
ButtonplusHome.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandleradd);
ButtonminusHome.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerminus);
//StartSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerSS);
//StopSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerStS);
ResetSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerRS);
Reset24.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler24);
ButtonplusGuest.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandleraddg);
ButtonminusGuest.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerminusg);
Seconds.text = "06:00";
Possesso.text = "24";
function stopstartF(e:MouseEvent):void
if(!e.currentTarget.toggle){
     timer.start()
     timer2.start();
MovieClip(e.currentTarget).gotoAndStop("stop");   // label the stop frame which contains the appropriate display
} else {
     timer.stop()
     timer2.stop();
MovieClip(e.currentTarget).gotoAndStop(1);  // your play display
e.currentTarget.toggle=!e.currentTarget.toggle;
function countdown(e:TimerEvent):void
     time.time = (timer.repeatCount - timer.currentCount) * 1000;
     Seconds.text = time.toString().match(timePattern)[0];
     if (timer.repeatCount == timer.currentCount) {
          playSound(Event);
function countdownpossesso(e:TimerEvent):void
     time.time = (timer2.repeatCount - timer2.currentCount) * 1000;
     Possesso.text = time.toString().match(secondPattern)[0];
     if (timer2.repeatCount == timer2.currentCount) {
          playSound(Event);
function playSound(Event):void {
   mySound.play()
   timer.stop()
function scoreFormat(value:Number):String
     return String(value <= 9 ? "0" + value : value);
function fl_MouseOverHandleradd(e:MouseEvent):void
     ScoreHome++;
     HomeScore.text = scoreFormat(ScoreHome);
function fl_MouseOverHandlerminus(e:MouseEvent):void
     ScoreHome--;
     HomeScore.text = scoreFormat(ScoreHome);
function fl_MouseOverHandlerRS(e:MouseEvent):void
     timer.reset()
     timer2.reset()
     timer.start()
     timer2.start()
     timer.stop()
     timer2.stop()
     Seconds.text = "06:00";
     Possesso.text = "24";
function fl_MouseOverHandleraddg(e:MouseEvent):void
     ScoreGuest++;
     GuestScore.text = scoreFormat(ScoreGuest);
function fl_MouseOverHandlerminusg(e:MouseEvent):void
     ScoreGuest--;
     GuestScore.text = scoreFormat(ScoreGuest);
function fl_MouseOverHandler24(e:MouseEvent):void
     timer2.reset()
     timer2.start()
     Possesso.text = "24";
var mySound:Sound = new Buzzer();

Similar Messages

  • How do I create a start/stop button for each separate while loop within my program, when each of them does a different task?

    I have a multimeter VI with separate while loops to accomplish the different tasks of reading  voltage, current, etc. Each while loop has a stop button, but I need a button that will have to be pressed in order for the while loop to even start. I tried putting another while loop around the present one, but it still has to run once before it will stop. I want the user to have to press the button before it runs, because they interfere with each other.
    I am just learning so patience and your kind assistance is greatly appreciated!
    ElectroKate

    iZACHdx wrote:
    Hello,
    I'm not entirely clear with everything you have going on and what you want your final functionality to be, but you can use sequence structures to prevent a loop from starting until the user presses a button like this:
    -Zach
    I have to ask, why is an NI employee using examples using sequence frames? The same thing could be accomplished using data flow by simply wiring the value of the first stop button out of teh first while loop and connecting it to the second loop. This would then use data flow to control the sequence. Why show new users bad programming methods?
    As to the original question I would concur with altenbach on using an event structure.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Start/Stop Buttons and infinite loop exit

    I am trying to make a GUI with a Start/Stop and an Exit button. Initially the button will have the label "Start". When i push it, its label should become "Stop" and an infinite loop function will begin. I want the loop to run until i press the Stop or Exit button.
    The problem is that when the loop starts i can't press neither of the buttons. The "Start" button changes its label into "Stop" only if i make the loop finite and it ends.
    Here is the source:
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class StartStopButtons extends JFrame{
        Component visualComponent = null;
        JPanel panel = null;
        JLabel statusBar = null;
         public StartStopButtons() {
              setSize(160, 70);
              getContentPane().setLayout(new BorderLayout());
            panel = new JPanel();
            panel.setLayout(new BorderLayout());
            getContentPane().add(panel, BorderLayout.CENTER);
            final JPanel panel_1 = new JPanel();
            panel.add(panel_1, BorderLayout.CENTER);
            final JButton startButton = new JButton();
            startButton.addActionListener(new ActionListener() {
                 public void actionPerformed(final ActionEvent e) {
                    String action = e.getActionCommand();
                    if (action.equals("Start")) {
                         System.out.println("Start Loop");
                         startButton.setText("Stop");
                         myLoop ();
                    if (action.equals("Stop")) {
                         System.out.println("Stop Loop");
                         System.exit(0);
            startButton.setText("Start");
            panel_1.add(startButton);
            final JButton exitButton = new JButton();
            exitButton.addActionListener(new ActionListener() {
                 public void actionPerformed(final ActionEvent e) {
                    String action = e.getActionCommand();
                    if (action.equals("Exit")) {
                        System.exit(0);
            panel_1.add(exitButton);
            exitButton.setText("Exit");
         public void myLoop() {
              for (int i = 0; ; i++)
                   System.out.println(i);
         public static void main(String[] args) {
              StartStopButtons ssB = new StartStopButtons();
              ssB.setVisible(true);
    }

    I works just fine. Here is the source and thanks for the help.
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.UIManager;
    public class StartStopButtons extends JFrame implements ActionListener, Runnable{
        Component visualComponent = null;
        JPanel panel = null;
        JLabel statusBar = null;
        Thread thread;
        JButton startButton;
         public StartStopButtons() {
            try {
                UIManager.setLookAndFeel(
                    UIManager.getSystemLookAndFeelClassName());
            } catch(Exception e) {}
              setSize(160, 70);
              getContentPane().setLayout(new BorderLayout());
            panel = new JPanel();
            panel.setLayout(new BorderLayout());
            getContentPane().add(panel, BorderLayout.CENTER);
            final JPanel panel_1 = new JPanel();
            panel.add(panel_1, BorderLayout.CENTER);
            startButton = new JButton();
            startButton.addActionListener(this);
            startButton.setText("Start");
            panel_1.add(startButton);
            final JButton exitButton = new JButton();
            exitButton.addActionListener(new ActionListener() {
                 public void actionPerformed(final ActionEvent e) {
                    String action = e.getActionCommand();
                    if (action.equals("Exit")) {
                        System.exit(0);
            panel_1.add(exitButton);
            exitButton.setText("Exit");
         public void actionPerformed(ActionEvent e) {
              String action = e.getActionCommand();
              if (action.equals("Start")) {
                   startButton.setText("Stop");
                   thread = new Thread( this );
                   thread.start();
              if (action.equals("Stop")) {
                System.exit(0);
         public void run() {
              myLoop();
         public void myLoop() {
              for (int i = 0; ; i++)
                   System.out.println(i);
         public static void main(String[] args) {
              StartStopButtons ssB = new StartStopButtons();
              ssB.setVisible(true);
    }

  • Single start/stop button for looping movie

    Dear Friends,
    I apologize if this has been addressed already in the forum, as I have had no luck searching here or the web in general for a solution.
    I currently have a 23-frame multilayered single-scene animation designed to loop continuously which I would like to add to my portfolio. As such, I am adding a Play button, which I would like to toggle to a Stop (or Pause) button. I currently have an instance of the Play button ("playButton") created.
    (You can find this at pineboxmovingco.com/gear_redux.swf)
    Besides imploring your assistance in providing the code, I must also ask if this requires (and best practice for) inserting an additional frame at the beginning for the ActionScript, as well as where/what layer to add an instance of the Stop button. I would like the movie to be stopped by default, presenting the Play button, toggling to the Stop button, and back to the Play button, each upon release.
    Thank you so much in advance!
    Michael T
    Phila, PA

    So, Ned, insert the stop(); command - with no other code - on each keyframe of the MC like so:
    Then, return to Scene 1 and select the MC, inserting the code:
    With an additional "stop" command in the first frame:
    I must be missing something as it is continues to loop. Any further assistance would be greatly appreciated...
    Michael
    (UPDATE: Replaced second image with AS reflecting replacement of XXX with "1".)
    Message was edited by: turnerator

  • AS 3.0 Output Error for Start / Stop Buttons

    In trying to understand ActionScript 3.0 mouse events, I have
    followed the online video under Flash / ActionScript / Getting
    Started wit ActionScript 3.0 presented by Justin Everett-Church. At
    least I don't see any syntax errors.
    I am not getting a Compiler error, but I get this warning in
    the Output tab: WARNING: Actions on button or MovieClip instances
    are not supported in ActionScript 3.0. All scripts on object
    instances will be ignored.
    I understand what it is telling me. Actions on button
    instances are not support in AS 3.0. But then why does the video
    tell me to name a button instance and then go on to refer to it in
    the ActionScript?
    The movie still works fine. I just get this Output warning.
    Should I be concerned? I am using Flash CS3 Professional Version
    9.0
    Another peculiar thing is this. The code shown below DOES NOT
    generate an Output error on one on my FLA files, but it DOES on
    three others that have exactly the same button names and AS 3.0
    code (shown below). I don't see any differences. I even copied and
    pasted the code from the one that didn't produce the warning to the
    others that did. Again, the movies seem to work fine, but I get the
    Output warning.
    Here is my ActionScript 3.0 code (I named the three button
    instances: stopBtn, playBtn, restartBtn)
    import flash.events.MouseEvent;
    stopBtn.addEventListener(MouseEvent.CLICK, stopDemo);
    function stopDemo(event:MouseEvent):void {
    this.stop();
    playBtn.addEventListener(MouseEvent.CLICK, playDemo);
    function playDemo(event:MouseEvent):void {
    this.play();
    restartBtn.addEventListener(MouseEvent.CLICK,restartDemo);
    function restartDemo(event:MouseEvent):void {
    this.stop();
    this.gotoAndPlay(1);

    Are you extending the layer that has the function for the length of the timeline like I showed in the example file I made for you?  I put the code for the other frames on a separate layer to make sure that the one being shared is not cut short.
    I think I also already mentioned that you should go into the Flash Publish Settings and select the option to Permit Debugging so that the error message indicates which line of code is causing the problem.

  • Start/stop buttons

    In Captivate 5.5 I have created two buttons, each button is assigned with a Conditional Action:
    Pause:
    If:
    rdcmndPause is equal to 0
    Action:
    Hide pause
    Show play2
    Assign rdcmndPause with 1
    Play:
    If:
    rdcmndResume is equal to 0
    Action:
    Hide play2
    Show pause
    Assign rdcmndResume with 1
    This works fine when the buttons are next to eachother. But when I put the buttons on top of eachother this only works for one time (Pause-Play).
    What can be the problem?

    You cannot put the two buttons in exact the same location, unless they are staggered on the timeline.
    I blogged about Pause/play button some time ago, and warned about that:
    http://lilybiri.posterous.com/custom-playpause-button-in-captivate
    Lilybiri

  • Start Stop and Run button.

    hello,
    I have one question, I want one button which can be run/start/stop button. I can't compile the program with "Run when open", because I need the user enter a string and a configuration, however after the user enter a configuration, I want that a START button, and when the user want press the same button to STOP all the program. All without pressing the "Run button (white arrow)". So the sequence it will be:
    1- open the ".exe"
    2- configure the variables such as: file name, file path, comments.....
    3- press START button, and the system will start acquisition.
    4- press STOP button and the program stopped and save all the data in a file.
    It is that possible? Could anyone help me with it? Or send me and example?
    Best regards,
    Anna.  

    Hi,
    You can do something like this.
    Compile it with "Run when open".
    Best regards
    Matej
    CLAD using LV 8.2, 2010 and 2012
    R&D Laboratories
    Domel d.o.o.
    www.domel.com
    Attachments:
    StartStopAndRun.vi ‏13 KB

  • AWT start/stop bundle buttons Help needed.

    Hello,
    I need help getting start/stop buttons on my AWT Class to take the action of methods from an other class. I will give anybody who can figure this out ALL OF MY Duke Dollars. (I shortend it up to the important stuff so that there isn't too much to read):
    MY PROBLEM: I need to have my Gui user interface to start up first. Then when somebody clicks the Gui class "start" button, it will call the start method of my Activator class and similiarly for the "stop" button. When I run the program, it starts up already in "start" mode. It should start up without getting the service (stop mode) and then get it once "start" is pressed" Hopefully somebody can help me figure this out.
    First, I have the following AWT class
    public class Gui extends Frame{
          Frame f;
          MyImage imagePanel;
          Button button_start;
          Button button_stop;
          Label statusBar;
          Panel btns;
        public Gui() {
            addWindowListener(new WinClosing());
            setLayout(new BorderLayout());
            imagePanel = new MyImage();
            btns = new Panel();
            button_start  = new Button("START");
            button_stop  = new Button("STOP");
            btns.add(button_start);
            btns.add(button_stop);
            add("North", btns);
            add("Center",imagePanel);       
            button_start.addActionListener(new ActionListener(){     
                public void actionPerformed( ActionEvent e ){
                    imagePanel.getImage();
            button_stop.addActionListener(new ActionListener(){     
                public void actionPerformed( ActionEvent e ){
                imagePanel.closeImage();}
            });          }Then I have the Activator class:
    public class Activator implements BundleActivator {
         public ServiceReference reference;
         public void start(BundleContext bc) {
             reference = bc.getServiceReference(GpsService.SERVICE_NAME);
             if (reference == null) {
             System.out.println("User could not get a service.");
              } else {
             AnyService anything = (AnyService) bc.getService(reference);
                    UserClass user = new UserClass();
                    user.startup(anything);
    public void stop(BundleContext bc) {
        if (reference != null) {
        bc.ungetService(reference);
        reference = null;
        System.out.println("User has released its Service.");
        } }}Then this previous class calls the startup method for this class:
    public class Driver {
            public void startup(AnyService any){
            double any  = any.getValue();
            System.out.println(any);
            Gui g = new Gui(any);
            g.setSize(714, 480);
            g.setVisible(true); 
          }}Thanks in advance!

    Hmm, it's quite hard to imagine what's going on without the code for MyImage. However, I guess you need to add an ActionListener to your two buttons. Are you sure you need two buttons, though? Presumably you can't stop until you've started and vice versa?
    private Activator activator;
    private Button startButton;
    private Button stopButton
    public Gui()
      startButton = new Button("Start");
      stopButton = new Button("Stop");
      stopButton.setEnabled(false);
      startButton.addActionListener(new ActionListener()
        public void actionPerformed(ActionEvent e)
          start();
      stopButton.addActionListener(new ActionListener()
        public void actionPerformed(ActionEvent e)
          stop();
    private synchronized void start()
      // Construct the Activator when we need it
      if(activator == null)
        activator = new Activator();
      activator.start(...); // Don't know where you get your BundleContext from!
      startButton.setEnabled(false);
      stopButton.setEnabled(true);
    private synchronized void stop()
      activator.stop(...); // Don't know where you get your BundleContext from!
      startButton.setEnabled(true);
      stopButton.setEnabled(false);
    }I'm assuming here that once the Activator is "started" is stays started until it is told to stop, ie, it doesn't stop itself after a finite amount of time.
    Hope this helps.

  • How to make a common RUN/STOP Button

    Hi,
    Does anyone has an example to make common START/STOP Button in main VI.
    Thanks,
    Kishor
    [email protected]

    I'm not sure what you are trying to achieve; do you want the start/stop button to pause the sequence and then commence where it was if start is pressed again?
    Using the state machine you can still force the execution order but have more control; you can stop the sequence whenever you want, skip frames based on user input or other...and you can have a single start/stop button.
    Attached is an example.
    MTO
    Attachments:
    Stoppable_sequence.vi ‏70 KB

  • When i plug my ipod in it says ipod cant be read cuz the apple mobile device is not started.And i went to services and apple mobile device properties and start stops in the middle.and its on automatic.and there isnt a stop button.

    when i plug my ipod in it says ipod cant be read cuz the apple mobile device is not started.And i went to services and apple mobile device properties and start stops in the middle.and its on automatic.and there isnt a stop button.when i click start it says the apple mobile device services stopped in the middle then stopped.it said some services stop in the middle if not used by other services.and i just updated itunes before all a this and ever since ive had errors.

    Have you looked at this article:
    iPhone, iPad, iPod touch: How to restart the Apple Mobile Device Service (AMDS) on Windows

  • How to add stop button in this code AS3

    Hello, im new to this adobe flash AS3. i want to create a simple play sound using flash + XML file for wbesite., this is my code
    all this code are working greate.. but i have the problem to add stop_btn code my playlist button already have pause, prevous and next and play.. only stop button i have fail to create. this is my code
    var my_songs:XMLList;
    var my_total:Number;
    var my_sound:Sound;
    var my_channel:SoundChannel;
    var current_song:Number = 0;
    var song_position:Number;
    var song_paused:Boolean;
    var myXMLLoader:URLLoader = new URLLoader();
    myXMLLoader.load(new URLRequest("playlist2.xml"));
    myXMLLoader.addEventListener(Event.COMPLETE, processXML);
    function processXML (e:Event):void{
    var myXML:XML = new XML(e.target.data);
    my_songs = myXML.SONG;
    my_total = my_songs.length();
    function playSong(mySong:Number):void{
    var myTitle = my_songs[mySong].@TITLE;
    var myArtist = my_songs[mySong].@ARTIST;
    var myURL = my_songs[mySong].@URL;
    title_txt.text = myTitle;
    artist_txt.text = myArtist;
    if (my_channel){
    my_channel.stop();
    my_sound = new Sound();
    my_sound.load(new URLRequest(myURL));
    my_channel = my_sound.play();
    my_channel.addEventListener(Event.SOUND_COMPLETE, onNext);
    next_btn.addEventListener(MouseEvent.CLICK, onNext);
    function onNext(e:Event):void{
    current_song++;
    if (current_song>=my_total){
    current_song=0;
    playSong(current_song);
    prev_btn.addEventListener(MouseEvent.CLICK, onPrev);
    function onPrev(e:MouseEvent):void{
    current_song--;
    if (current_song<0){
    current_song = my_total-1;
    playSong(current_song);
    pause_btn.addEventListener(MouseEvent.CLICK, onPause);
    function onPause(e:MouseEvent):void{
    if (my_channel){
    song_position = my_channel.position;
    my_channel.stop();
    song_paused=true;
    play_btn.addEventListener(MouseEvent.CLICK, onPlay);
    function onPlay(e:MouseEvent):void{
    if (song_paused){
    my_channel = my_sound.play(song_position);
    song_paused=false;
    } else if (!my_channel){
    playSong(current_song);
    can some one help with me... thank you

    stop_btn.addEventListener(MouseEvent.CLICK, onStop);
    function onStop(e:MouseEvent):void{
       if (my_channel){
          my_channel.stop();

  • Action Script 3 code not working for start and stop button?

    Ok so I have this simple animation I created of a circle that moves from one side of the stage to the other. I have added a new layer and called it buttons. On this layer I have added 2 buttons. One for start and another one for stop. The purpose is to get my circle to move from one side of the stage to the other but be able to use my buttons so that I can start and stop the animations at random times during playback. I fixed all my compiler errors now the problem lies in that everytime I click the start or the stop button I get an output error. I have a 3rd layer in which is titled actions and this is where all my code is posted. I removed that layer and placed my code in the first frame of the buttons layer to see if this would change anything but I still get the same output errors. So I just added back my actions layer. What could I be doing wrong? I have made sure to name all my movie clips and buttons correctly and I even added an instance name to them.
    Here is my code and the errors I am getting when I press the play and stop button on test-
    start_btn.addEventListener(MouseEvent.CLICK, startCircle);
    stop_btn.addEventListener(MouseEvent.CLICK, stopCircle);
    function startCircle(e:MouseEvent):void{
        circle.play();
    function stopCircle(e:MouseEvent):void{
        circle.stop();
    green_btn.addEventListener(MouseEvent.CLICK, greenCircle);
    red_btn.addEventListener(MouseEvent.CLICK, redCircle);
    function greenCircle(e:MouseEvent):void{
        circle.play();
    function redCircle(e:MouseEvent):void{
        circle.stop();
    Here are my output errors-
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
        at exercise2_fla::MainTimeline/redCircle()
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
        at exercise2_fla::MainTimeline/greenCircle()

    ok so my circle is my movie clip and it is titled circle and the instance name is circle. Am I supposed to change MovieClip to circle? I put the code at the top of my actions script but for some reason it did not work. I did change play to stop and it got the movie clip to stop when I do test movie but my buttons still do not work. So I changed stop back to play. Strange.
    I did try changing MovieClip to circle but that did not work so I did Circle with a capital C and that did me no good eigther.
    I meant to add that I did get an error that said- 1180 Call to a possibly undefined method circle.

  • HT1657 I downloaded a movie, but when I go to play it the play button to typically start it is the "stop" button instead.  How do I fix this?

    I downloaded a movie, but when I go to play it the play button to typically start it is the "stop" button instead.  How do I fix this?

    Are you getting an "iTunes has stopped working" message after the black, screen? Or is something a bit different going on?

  • Controlling sound file with play, stop and mute button in AS3.0?

    the method for stopping/playing sound in 2.0 don't work for 3.0.  i can stop the sound by going to a different page/frame on the site.  but i want the buttons. 
    1. play button?
    2.stop button?
    3.mute button?
    thanks in advance!

    for pause (example 2) :
    for volume -mute (example 1) :
    package
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.*;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.SoundTransform;
    import flash.net.URLRequest;
    import flash.utils.Timer;
    public class SoundTransformExample extends Sprite
      private var url:String = "MySound.mp3";
      private var soundFactory:Sound;
      private var channel:SoundChannel;
      private var positionTimer:Timer;
      public function SoundTransformExample()
       stage.align = StageAlign.TOP_LEFT;
       stage.scaleMode = StageScaleMode.NO_SCALE;
       var request:URLRequest = new URLRequest(url);
       soundFactory = new Sound();
       soundFactory.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
       soundFactory.load(request);
       channel = soundFactory.play();
       stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
      private function ioErrorHandler(event:Event):void
       trace("ioErrorHandler: " + event);
      private function setPan(pan:Number):void
       trace("setPan: " + pan.toFixed(2));
       var transform:SoundTransform = channel.soundTransform;
       transform.pan = pan;
       channel.soundTransform = transform;
      private function setVolume(volume:Number):void
       trace("setVolume: " + volume.toFixed(2));
       var transform:SoundTransform = channel.soundTransform;
       transform.volume = volume;
       channel.soundTransform = transform;
      private function mouseMoveHandler(event:MouseEvent):void
       var halfStage:uint = Math.floor(stage.stageWidth / 2);
       var xPos:uint = event.stageX;
       var yPos:uint = event.stageY;
       var value:Number;
       var pan:Number;
       if (xPos > halfStage)
        value = xPos / halfStage;
        pan = value - 1;
       else if (xPos < halfStage)
        value = (xPos - halfStage) / halfStage;
        pan = value;
       else
        pan = 0;
       var volume:Number = 1 - (yPos / stage.stageHeight);
       setVolume(volume);
       setPan(pan);
     package
    import flash.display.Sprite;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.text.TextField;
    import flash.events.MouseEvent;
    import flash.text.TextFieldAutoSize;
    public class SoundChannel_stopExample extends Sprite
      private var snd:Sound = new Sound();
      private var channel:SoundChannel = new SoundChannel();
      private var button:TextField = new TextField();
      public function SoundChannel_stopExample()
       var req:URLRequest = new URLRequest("MySound.mp3");
       snd.load(req);
       button.x = 10;
       button.y = 10;
       button.text = "PLAY";
       button.border = true;
       button.background = true;
       button.selectable = false;
       button.autoSize = TextFieldAutoSize.CENTER;
       button.addEventListener(MouseEvent.CLICK, clickHandler);
       this.addChild(button);
      private function clickHandler(e:MouseEvent):void
       var pausePosition:int = channel.position;
       if (button.text == "PLAY")
        channel = snd.play(pausePosition);
        button.text = "PAUSE";
       else
        channel.stop();
        button.text = "PLAY";

  • How to terminate or exit a for loop when the user clicks on stop button

    Actually my problem is to stop a loop when i click on stop button.
    example:i have two buttons 'start' and 'stop'
    in start buttom i wrote a for loop as
    dim i as integer
    For i=1 To 100000
    print i
    Next
    when i click on start buuton it prints 'i' value up tp 100000.
    my question is when i click on 'Stop' button the for loop has to terminate or Exit from the  loop and should stops the execution.
    Is it possible to termianate or Exit the 'for loop'
    PS.Shakeer Hussain
    Hyderabad

    I am unable to stop the loop and application not at all allowing to Press the Stop button.
    It seems like Hung, any advise ?
    Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
            btnStop.Enabled = True
            btnSelectFile.Enabled = False
            btnStart.Enabled = False
            btnStop.Focus()
            Dim strFileName As String = txtFileName.Text.ToString
            Dim strLineText As String
            If System.IO.File.Exists(strFileName) = True Then
                Dim objReader As New System.IO.StreamReader(strFileName)
                While objReader.Peek() <> -1 And stopclick = False
                    strLineText = objReader.ReadLine()
                    MsgBox(strLineText, MsgBoxStyle.Information)
                    Application.DoEvents()
                    Thread.Sleep(My.Settings("strDelay") * 1000)
                    'System.Diagnostics.Process.Start(My.Settings("strFireFoxLocation"), strLineText)
                End While
            End If
        End Sub
        Private Sub btnStop_Click(sender As Object, e As EventArgs) Handles btnStop.Click
            stopclick = True
            btnSelectFile.Enabled = True
            btnStart.Enabled = True
            btnStop.Enabled = False
        End Sub
    Raman Katwal
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • HT201272 What is it with songs that are not from the itunes store, but are coming from cd's and other download sources that all of a sudden do not play on my iphone and have a red stop button in a red round circle around them, behind the title?

    Songs that I have had previously downloaded from various other sources, but NOW ALL of a sudden they DO NOT PLAY on my IPHONE and DISPLAY a RED STOP BUTTON in a red round circle next to the title.  Everytime I click on it it DOESNT play.   What happen???? How can i get them to play.,   Why should i have to pay for the songs, and why are they in the ITUNES store and not in my regular playlist.

    Amazing steps you've done so far! The great news is this is very unlikely an issue with your iPhone.
    I've run into a similar issue lately as well. I narrowed it down to one song that was causing 30 songs not to sync. I removed the song from the sync list (unchecked it) and all 29 songs were able to sync.
    You may be running into a similar issue. This may be a problem with this version of iTunes, an issue with one song or a group of songs; hard to know for sure. It's important to narrow down and isolate the cause. Most imporantly get that music back on there!
    The way to narrow down the casue add just a few songs at a time (even 1, just to get that first sync finished). Manually syncing is what you'll need here.
    Plug in your iPhone, on the Summary screen (shows a picture of your iPhone, the iOS version, Restore iPhone....; etc). Under the Options area at the bottom choose to Manually Manage Videos and Music then choose Apply in the lower right. The music that's on your iPhone now should be removed from your iPhone now. You're now able to sync music manually.
    The link below explains how to drag the songs from the iTunes library on the computer on to your iPhone which will start the sync. Add just one song just to see if you can get 1 of those hundreds of songs on there. If you can, awesome! Keep adding until you find the song or group of songs that are causing this issue.
    http://support.apple.com/kb/HT1535
    Please let me know how things are going.
    Cheers!

Maybe you are looking for