Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Is there a simpler way to do this?

Reply
Thread Tools

Is there a simpler way to do this?

 
 
Ritchie Valens
Guest
Posts: n/a
 
      07-30-2011


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 !!!
 
Reply With Quote
 
 
 
 
Ritchie Valens
Guest
Posts: n/a
 
      07-30-2011

Any Suggestions?



On Sat, 30 Jul 2011 02:46:25 +0100, Ritchie Valens <(E-Mail Removed)>
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 !!!
 
Reply With Quote
 
 
 
 
Luuk
Guest
Posts: n/a
 
      07-30-2011
On 30-07-2011 21:02, Ritchie Valens wrote:
>
> Any Suggestions?
>
>
>
> On Sat, 30 Jul 2011 02:46:25 +0100, Ritchie Valens <(E-Mail Removed)>
> 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


....

--
Luuk
 
Reply With Quote
 
Ritchie Valens
Guest
Posts: n/a
 
      07-31-2011

How different is Javascript than actionscript 3.0 ?


On Sat, 30 Jul 2011 21:09:27 +0200, Luuk <(E-Mail Removed)> wrote:

>On 30-07-2011 21:02, Ritchie Valens wrote:
>>
>> Any Suggestions?
>>
>>
>>
>> On Sat, 30 Jul 2011 02:46:25 +0100, Ritchie Valens <(E-Mail Removed)>
>> 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 !!!
 
Reply With Quote
 
John G Harris
Guest
Posts: n/a
 
      07-31-2011
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 <(E-Mail Removed)>
>> 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
 
Reply With Quote
 
Ritchie Valens
Guest
Posts: n/a
 
      07-31-2011


John,

Thanks.

Regards


On Sun, 31 Jul 2011 16:53:36 +0100, John G Harris
<(E-Mail Removed)> 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 <(E-Mail Removed)>
>>> 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 !!!
 
Reply With Quote
 
Scott Sauyet
Guest
Posts: n/a
 
      08-16-2011
On Jul 29, 9:46*pm, Ritchie Valens <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a simpler way to modify all arguments in a function beforeusing the arguments? bruceg113355@gmail.com Python 20 11-16-2012 09:30 PM
Is there a better/simpler way to filter blank lines? tmallen Python 19 11-05-2008 11:07 PM
Is there a simpler way to do this? Julian Leviston Ruby 12 08-27-2005 11:16 PM
Is there a simpler way (trick) to create composite controls ? Alex Nitulescu ASP .Net 5 03-03-2005 11:17 AM
super. could there be a simpler super? Kerim Borchaev Python 4 01-15-2004 03:15 PM



Advertisments