473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Cutting code down using parameters in functions

Hi all, first post here.

Found this site using Google while trying to figure out why I couldn't add a URL to a button and thanks to an existing question on here, I've done it. Problem is, seems long-winded. Here's my code:

Expand|Select|Wrap|Line Numbers
  1. btnHomePage.addEventListener(MouseEvent.CLICK,callHomePage);
  2. btnAboutUs.addEventListener(MouseEvent.CLICK,callAboutUs);
  3. btnFacilities.addEventListener(MouseEvent.CLICK,callFacilities);
  4. btnContactUs.addEventListener(MouseEvent.CLICK,callContactUs);
  5.  
  6. function callHomePage(event:MouseEvent):void {
  7.   var url:String="home.php";
  8.   var request:URLRequest=new URLRequest(url);
  9.   try {
  10.     navigateToURL(request,'');
  11.   } catch (e:Error) {
  12.     trace("Error occurred with Home Page");
  13.   }
  14. }
  15.  
  16. function callAboutUs(event:MouseEvent):void {
  17.   var url:String="aboutus.php";
  18.   var request:URLRequest=new URLRequest(url);
  19.   try {
  20.     navigateToURL(request,'');
  21.   } catch (e:Error) {
  22.     trace("Error occurred with About Us");
  23.   }
  24. }
  25.  
  26. function callFacilities(event:MouseEvent):void {
  27.   var url:String="facilities.php";
  28.   var request:URLRequest=new URLRequest(url);
  29.   try {
  30.     navigateToURL(request,'');
  31.   } catch (e:Error) {
  32.     trace("Error occurred with Facilities");
  33.   }
  34. }
  35.  
  36. function callFacilities(event:MouseEvent):void {
  37.   var url:String="contactus.php";
  38.   var request:URLRequest=new URLRequest(url);
  39.   try {
  40.     navigateToURL(request,'');
  41.   } catch (e:Error) {
  42.     trace("Error occurred with Contact Us");
  43.   }
  44. }
Now I'm used to other languages. I've been programming on almost everything since the early 1980s like BASIC on the Commodore 64 and BBC machines, assembler on the Amiga and PHP/MySQL online. The logical way of passing the URL as a parameter to cut down on masses of code is giving me nothing but error message after error message.

Anyone able to help me cut this mass of code down to only one function with the URL being passed each time please?

I'm using Adobe Flash CS9 Professional and loaded it yesterday for the first time after buying a (thick) book which claims to be also for beginners but its lost me already.

Having to learn Flash for the business - thought I could get away without it :(
Feb 22 '08 #1
0 1527

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Liberal | last post by:
I am looking for the simplest forum, bbs script which has those features? new messages will be displayed only after the administrator reviewed allow users post without signing up display the...
242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
9
by: Steve Jorgensen | last post by:
First, an example - today, I wanted to print out the parameter values in a querydef object at a break point in the code for subsequent manual debugging of the query. In the past, I would have had...
15
by: Jean | last post by:
Hello, I have the following query that I set up as a test, and it runs fine: SELECT STATUSHISTORIE.* FROM STATUSHISTORIE LEFT JOIN PROBLEM_DE ON STATUSHISTORIE.PROBLEM_ID =...
41
by: Jordan | last post by:
While writing some code, I realized I had never developed a consistent pattern for checking errors from a method. I have two styles I jump back and forth between, but I'm wondering which is...
4
by: pauldepstein | last post by:
I am writing code to price some financial options using recursive functions. It compiles but I get a runtime error which is caused by a memory violation. The problem is that the code is much...
8
by: goldfita | last post by:
I love this place. This one problem keeps coming back to bite me. Suppose I have the following situation (actually I do). func1() { codeA somefunc1() codeB }
0
by: peridian | last post by:
Hi, I wanted a web page where I could post code to, and have it appear in coloured formatting based on the context of the code. Most of the techniques I have seen for this involve complex use...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.