Is there a simpler way to do this?

Discussion in 'Javascript' started by Ritchie Valens, Jul 30, 2011.

  1. Hi,



    I was wondering, how different is Javascript, from Actionscript 3.0?

    I am messing around with a web radio application, I am trying to
    create.

    I am a newbie but more used to AS 2.0, but I finally took the plunge
    and forced myself to learn AS 3.0.

    Basically everytime a button is pressed, it goes to the next Radio
    Station:

    As Below, but I think there must be a simpler way, without repeating
    the code.

    Any suggestions,

    Please keep it simple, and would you be kind enough to explain, what
    you have done?


    The right Braces at the end bother me, they look silly, which is why I
    thought there is an easier way






    Regards





    //Stop Script

    stop();


    // up Button Script Jazz fm

    up_btn.addEventListener(MouseEvent.CLICK, btn1);
    function btn1 ( event:MouseEvent):void
    { navigateToURL (new URLRequest ("http://www.jazzfm.com"));

    gotoAndStop(2);


    up_btn.addEventListener(MouseEvent.CLICK, btn1);
    function btn1 ( event:MouseEvent):void
    { navigateToURL (new URLRequest ("http://www.bbc.co.uk/radio1"));


    up_btn.addEventListener(MouseEvent.CLICK, btn1);
    function btn1 ( event:MouseEvent):void
    { navigateToURL (new URLRequest ("http://www.bbc.co.uk/radio2"));


    up_btn.addEventListener(MouseEvent.CLICK, btn1);
    function btn1 ( event:MouseEvent):void
    { navigateToURL (new URLRequest ("http://www.bbc.co.uk/radio3"));


    up_btn.addEventListener(MouseEvent.CLICK, btn1);
    function btn1 ( event:MouseEvent):void
    { navigateToURL (new URLRequest ("http://www.bbc.co.uk/radio4"));


    }}}}}
    Life is Good !!!
     
    Ritchie Valens, Jul 30, 2011
    #1
    1. Advertising

  2. Any Suggestions?



    On Sat, 30 Jul 2011 02:46:25 +0100, Ritchie Valens <>
    wrote:

    >
    >
    >Hi,
    >
    >
    >
    >I was wondering, how different is Javascript, from Actionscript 3.0?
    >
    >I am messing around with a web radio application, I am trying to
    >create.
    >
    >I am a newbie but more used to AS 2.0, but I finally took the plunge
    >and forced myself to learn AS 3.0.
    >
    >Basically everytime a button is pressed, it goes to the next Radio
    >Station:
    >
    >As Below, but I think there must be a simpler way, without repeating
    >the code.
    >
    >Any suggestions,
    >
    >Please keep it simple, and would you be kind enough to explain, what
    >you have done?
    >
    >
    >The right Braces at the end bother me, they look silly, which is why I
    >thought there is an easier way
    >
    >
    >
    >
    >
    >
    >Regards
    >
    >
    >
    >
    >
    >//Stop Script
    >
    >stop();
    >
    >
    >// up Button Script Jazz fm
    >
    >up_btn.addEventListener(MouseEvent.CLICK, btn1);
    >function btn1 ( event:MouseEvent):void
    >{ navigateToURL (new URLRequest ("http://www.jazzfm.com"));
    >
    >gotoAndStop(2);
    >
    >
    >up_btn.addEventListener(MouseEvent.CLICK, btn1);
    >function btn1 ( event:MouseEvent):void
    >{ navigateToURL (new URLRequest ("http://www.bbc.co.uk/radio1"));
    >
    >
    >up_btn.addEventListener(MouseEvent.CLICK, btn1);
    >function btn1 ( event:MouseEvent):void
    >{ navigateToURL (new URLRequest ("http://www.bbc.co.uk/radio2"));
    >
    >
    >up_btn.addEventListener(MouseEvent.CLICK, btn1);
    >function btn1 ( event:MouseEvent):void
    >{ navigateToURL (new URLRequest ("http://www.bbc.co.uk/radio3"));
    >
    >
    >up_btn.addEventListener(MouseEvent.CLICK, btn1);
    >function btn1 ( event:MouseEvent):void
    >{ navigateToURL (new URLRequest ("http://www.bbc.co.uk/radio4"));
    >
    >
    >}}}}}
    >Life is Good !!!


    Life is Good !!!
     
    Ritchie Valens, Jul 30, 2011
    #2
    1. Advertising

  3. Ritchie Valens

    Luuk Guest

    Luuk, Jul 30, 2011
    #3
  4. How different is Javascript than actionscript 3.0 ?


    On Sat, 30 Jul 2011 21:09:27 +0200, Luuk <> wrote:

    >On 30-07-2011 21:02, Ritchie Valens wrote:
    >>
    >> Any Suggestions?
    >>
    >>
    >>
    >> On Sat, 30 Jul 2011 02:46:25 +0100, Ritchie Valens <>
    >> wrote:
    >>
    >>>
    >>>
    >>> Hi,
    >>>
    >>>
    >>>
    >>> I was wondering, how different is Javascript, from Actionscript 3.0?

    >
    >read these two web-pages:
    >1) http://en.wikipedia.org/wiki/ActionScript
    >2) http://en.wikipedia.org/wiki/JavaScript
    >
    >This newsgroup is about JavaScript
    >
    >
    >...


    Life is Good !!!
     
    Ritchie Valens, Jul 31, 2011
    #4
  5. On Sat, 30 Jul 2011 at 21:09:27, in comp.lang.javascript, Luuk wrote:
    >On 30-07-2011 21:02, Ritchie Valens wrote:
    >>
    >> Any Suggestions?
    >>
    >>
    >>
    >> On Sat, 30 Jul 2011 02:46:25 +0100, Ritchie Valens <>
    >> wrote:
    >>
    >>>
    >>>
    >>> Hi,
    >>>
    >>>
    >>>
    >>> I was wondering, how different is Javascript, from Actionscript 3.0?

    >
    >read these two web-pages:
    >1) http://en.wikipedia.org/wiki/ActionScript
    >2) http://en.wikipedia.org/wiki/JavaScript
    >
    >This newsgroup is about JavaScript


    This news group is on topic for *any* language derived from ECMAScript.
    That includes ActionScript as well as JScript and JavaScript.

    That said, ActionScript has a lot of features that are not in the
    current JavaScript and JScript languages so answers might be slow in
    arriving.

    John
    --
    John Harris
     
    John G Harris, Jul 31, 2011
    #5
  6. John,

    Thanks.

    Regards


    On Sun, 31 Jul 2011 16:53:36 +0100, John G Harris
    <> wrote:

    >On Sat, 30 Jul 2011 at 21:09:27, in comp.lang.javascript, Luuk wrote:
    >>On 30-07-2011 21:02, Ritchie Valens wrote:
    >>>
    >>> Any Suggestions?
    >>>
    >>>
    >>>
    >>> On Sat, 30 Jul 2011 02:46:25 +0100, Ritchie Valens <>
    >>> wrote:
    >>>
    >>>>
    >>>>
    >>>> Hi,
    >>>>
    >>>>
    >>>>
    >>>> I was wondering, how different is Javascript, from Actionscript 3.0?

    >>
    >>read these two web-pages:
    >>1) http://en.wikipedia.org/wiki/ActionScript
    >>2) http://en.wikipedia.org/wiki/JavaScript
    >>
    >>This newsgroup is about JavaScript

    >
    >This news group is on topic for *any* language derived from ECMAScript.
    >That includes ActionScript as well as JScript and JavaScript.
    >
    >That said, ActionScript has a lot of features that are not in the
    >current JavaScript and JScript languages so answers might be slow in
    >arriving.
    >
    > John


    Life is Good !!!
     
    Ritchie Valens, Jul 31, 2011
    #6
  7. Ritchie Valens

    Scott Sauyet Guest

    On Jul 29, 9:46 pm, Ritchie Valens <> wrote:
    > Basically everytime a button is pressed, it goes to the next Radio
    > Station:
    >
    > As Below, but I think there must be a simpler way, without repeating
    > the code.


    You're instincts are right. There is a cleaner way. There must be.
    I have one below in regular javascript. I can't imagine it would be
    difficult to do in ActionScript.

    > The right Braces at the end bother me, they look silly, which is why I
    > thought there is an easier way


    > up_btn.addEventListener(MouseEvent.CLICK, btn1);
    > function btn1 ( event:MouseEvent):void
    > { navigateToURL (new URLRequest ("http://www.jazzfm.com"));
    >
    > gotoAndStop(2);
    >
    > up_btn.addEventListener(MouseEvent.CLICK, btn1);
    > function btn1 ( event:MouseEvent):void
    > { navigateToURL (new URLRequest ("http://www.bbc.co.uk/radio1"));
    > // ... [several more elided] ...
    > }}}}}


    Here's one approach:

    <p>Now playing: <span id="result">Current Station will
    go here</span>.</p>
    <button id="next" onclick="nextStation()">Next</button>

    var urls = [
    "http://www.jazzfm.com",
    "http://www.bbc.co.uk/radio1",
    "http://www.bbc.co.uk/radio2",
    "http://www.bbc.co.uk/radio3",
    "http://www.bbc.co.uk/radio4"
    ];
    nextStation = (function() {
    var result = document.getElementById("result"),
    count = urls.length,
    current = count;
    return function() {
    current = (current + 1) % count
    result.innerHTML = urls[current]; // change as needed
    };
    }());

    You can see this approach at

    <http://jsfiddle.net/CrossEye/a4KLJ/>

    (Sorry this is so late. Just returned from a vacation.)

    -- Scott
     
    Scott Sauyet, Aug 16, 2011
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Nitulescu
    Replies:
    5
    Views:
    1,349
    Alan Silver
    Mar 3, 2005
  2. Kerim Borchaev

    super. could there be a simpler super?

    Kerim Borchaev, Jan 15, 2004, in forum: Python
    Replies:
    4
    Views:
    479
    Michele Simionato
    Jan 15, 2004
  3. tmallen
    Replies:
    19
    Views:
    555
    Miles
    Nov 5, 2008
  4. Julian Leviston

    Is there a simpler way to do this?

    Julian Leviston, Aug 17, 2005, in forum: Ruby
    Replies:
    12
    Views:
    232
    Serpent
    Aug 28, 2005
  5. Replies:
    20
    Views:
    380
    Ethan Furman
    Nov 16, 2012
Loading...

Share This Page