Is there a simpler way to do this?

R

Ritchie Valens

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 !!!
 
R

Ritchie Valens

Any Suggestions?



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 !!!
 
R

Ritchie Valens

John,

Thanks.

Regards


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 !!!
 
S

Scott Sauyet

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top