Optional Parameter
How do i program an optional paramater funtion ?
eg. i want to be able to say like Update() OR Update(type)
Will i need to make two functions ?
function Update(){
}
function Update(type:String){
}
or can i just make one ? ( since this will keep code cleaner )
ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 07-10-2006, 11:13 AM
View Complete Forum Thread with Replies
Sponsored Links:
Optional Array As A Parameter
how do you do this? specifically for a class constructor.
this is what i tried:
Code:
public function MyClass(optional_int:int = 0, optional_array:Array = null){}
and:
Code:
public function MyClass(optional_int:int = 0, optional_array:Array = Array(0)){}
but i get compiler errors. so i ended up having to do on of these
Code:
public function MyClass(optional_int:int = 0, ... args){}
this feels wrong... and does provide different functionality than what i'm after (but works to accept an optional Array)
any ideas?
View Replies !
View Related
Using Only 1 Optional Parameter In A Class Method
Is it possible to use, say 3rd optional parameter in a built in class method? I'm trying to use the draw method of the Bitmap class with the clipRect parameter only but it says 'type mismatch' probably because I'm not declaring any of the previous optional parameters.
The original method of the bitmap class is the following, and I'm trying to use the bold parameter only:
public draw(source:Object, [matrix:Matrix], [colorTransform:ColorTransform], [blendMode:Object], [clipRect:Rectangle], [smooth:Boolean]) : Void
Any ideas?
View Replies !
View Related
Optional Zoom
I am making a 2d duck hunt type game and i am using the mask option to create a zoom effect in the scope/aimer. I have gotten it to work but i am having trouble making it possible for the user to zoom in even more. I try to make it so when the up or down arrows are pressed you zoom in or out. I have gotten the larger picture of the background to increase in size to make it appear as though you are zooming in but i can't get the picture to line up with the normal sized picture. This is the function i am using for the zoom option:
bigbckground is the larger picture that is giving the zoom effect
scope and zoom are the aimer and the maskover it so it can zoom
bigzoom is the variable being used to increase and decrease the zoom effect
bigzoom=0
zoombigbackground = function () {
scope._x = _xmouse;
scope._y = _ymouse;
zoom._x = _xmouse;
zoom._y = _ymouse;
Mouse.hide();
bigbackground._x = (-1)*_xmouse;
//this is aligning it for regular zoom
bigbackground._y = (-1)*_ymouse;
if (Key.isDown(Key.UP)) {
bigzoom += 2;
bigbackground._xscale = bigbackground._xscale*2;
bigbackground._yscale = bigbackground._yscale*2;
bigbackground._x = (-1)*bigzoom*_xmouse;
bigbackground._y = (-1)*bigzoom*_ymouse;
//this is where i have problems with it algining the big picture^
}
if (Key.isDown(Key.DOWN)) {
bigzoom -= 2;
bigbackground._xscale = bigbackground._xscale/2;
bigbackground._yscale = bigbackground._yscale/2;
bigbackground._x = (-1)*bigzoom*_xmouse;
bigbackground._y = (-1)*bigzoom*_ymouse;
}
};
If any can help me please do. THANKS!!
View Replies !
View Related
Optional Parameters
Hello,
I have always wondered about optional function parameters.
Lets say i have a function below:
Code:
function cookies (tastes_good:Boolean, is_big:Boolean, amount_of_chips:Number) {
if (tastes_good) {
trace("i taste good");
}
if(is_big) {
trace("i am big");
}
if(isNaN(amount_of_chips)) {
}
if(amount_of_chips == null) {
}
if(amount_of_chips == undefined) {
}
}
which is the proper way of checking if amount_of_chips has been set. Is there a way of saying amount of chips is option right were u pass in the parameters? something like you can with objects:
function cookies (tastes_good:Boolean, is_big:Boolean, {amount_of_chips:Number}) {
or can you set a default number that will get reset if I pass something in:
function cookies (tastes_good:Boolean, is_big:Boolean, amount_of_chips:Number = 0) {
View Replies !
View Related
Optional Parameters
I have this function:
ActionScript Code:
MovieClip.prototype.changeColor = function(mode, kl, kh, rl, rh, gl, gh, bl, bh) {bla, bla, bla...}
How can I make all parameters optional except the first one?
Thanks
View Replies !
View Related
Optional Parameters
I have this function:
ActionScript Code:
MovieClip.prototype.changeColor = function(mode, kl, kh, rl, rh, gl, gh, bl, bh) {bla, bla, bla...}
How can I make all parameters optional except the first one?
Thanks
View Replies !
View Related
Optional Floating Exponent
Flash outputs 0.0000000000056 as 5.6e-12. I do not want the "optional floating exponent". I want 0.0000000000056. Is it possible?
I ask because I'm making a math game for kids in converting small numbers into scientific notation and I want them to change 0.0000000000056 into 5.6 x 10^-12 manually.
View Replies !
View Related
Class With Optional Arguments
I would like to create a class for a project I'm working on. This class would be used for cables that are unplugged and replaced, some of which are tested with a multimeter. The issue is that, if the cable doesn't need to be tested at all, it is possible to simply unplug it then replace it from the unplugged state. Other cables, however, need to have certain pins tested for voltage and thus need to go to what we call the "face" of the cable (the part that plugs into the outlet).
My first thought for a class was to have a couple of optional arguments that would be used to give the appropriate pins needed for a test, if in fact the cable would be tested. But can I make a class with optional arguments?
Chris
View Replies !
View Related
Optional Form Fields
Can anyone help me to make two of my form fields not required for submitting the form?
I need the 'phone' and 'situation_comments' fields to be optional.
Here is my code...
TEMPty_mc._visible = false;
fielderror_mc._visible = false;
t=this;
tfArray = ['name','email','phone','role','situation','situation_comments','equity','email_fields','rid','email_subject'];
submitBtn.onPress = function() {
entry=true;
sendLV = new LoadVars();
for (var i = 0; i<tfArray.length; i++) {
//check fields for entry
if(t[tfArray].text.length<1) {
entry=false;
break;
}
sendLV[tfArray] = t[tfArray].text;
}
if(entry) {
//send email request **CHANGE THIS PHP ADDRESS**
sendLV.sendAndLoad('http://as2.omni1031.com/RepSupport/contact',receiveLV,'_POST');
}else{
//display error message
fieldError();
}
};
receiveLV = new LoadVars();
receiveLV.onLoad = function() {
//do whatever: message sent successfully (thank you + info page or something)
TEMPty_mc._visible = true;
//in this case I've turned off all the text fields and the buttons
for(var i=0;i<tfArray.length;i++) {
t[tfArray]._visible = false;
}
submitBtn.enabled=false;
};
//display error message handling
var fielderror_id:Number;
function fieldError() {
submitBtn._visible = false;
submitBtn.enabled = false;
fielderror_mc._visible = true;
clearInterval(fielderror_id);
fielderror_id=setInterval(this, "time", 3000);
}
function time() {
clearInterval(fielderror_id);
fielderror_mc._visible = false;
submitBtn._visible = true;
submitBtn.enabled = true;
}
View Replies !
View Related
Optional Commentary With Video
Hi
I have a bunch of swf videos (i want to stay compatible with player v6) compressed using squeeze.
I would like to add a "directors commentary" as an alternate audio track for each clip - a different commentary for each clip.
I am wondering what the simplest way to do this?
Thanks for any help -
View Replies !
View Related
Having Optional In Function Parameters
How do I go about setting up a function to optionally take a parameter? For example, to call a function like the following
test(1,2,3)
test(1,2,3,4)
Both of these would call the same function, but parameter 4 is optional. I have done this in VB.NET with 'Optional' and I can default the missing parameter. Is this possible in AS?
thanks,
the skOObs
View Replies !
View Related
Optional Commentary With Video
Hi
I have a bunch of swf videos (i want to stay compatible with player v6) compressed using squeeze.
I would like to add a "directors commentary" as an alternate audio track for each clip - a different commentary for each clip.
I am wondering what the simplest way to do this?
Thanks for any help -
View Replies !
View Related
Define Constructor With Optional Parameters
Hi,
I'm creating a class and I'd like to have some optional parameters in my constructor. Can I do this by simply defining parameters and then not passing them if I don't need to, or is there a better, cleaner way to do this.
eg
code:
class FooBar {
FooBar (aMandatory, anOptional) {
trace (aMandatory);
trace (anOptional);
}
}
Then, I'd like to be able to call it either as:
code:
FooGuy = new FooBar ("Happy");
FooGirl = new FooBar ("Happy", "Sad");
This appears to work as I've done it, but I'm wondering if something will break that I'm not seeing right now!
Barrette
View Replies !
View Related
How To Organize Classes For Optional Inclusion?
I have Flash MX 2004. I want to write some actionscript classes that i can import into my Flash projects. I want someone using my classes to be able to choose which class will be used to encode data. Is there a way that my main class (let's call it Service) can choose which file to reference for another class for data encoding? For instance, if I want my Service class to be a communication channel and I want to have it encode data as XML i could choose a class called SerializeXML. If I wanted my data encoded as a PHP object, i would use SerializePHP.
Ideally using my main Service class in your Flash file would not bloat your project unnecessarily by compiling a Serialize class that doesn't get used. For instance if I'm developing my Flash project to speak with a PHP server, there would be no need for SerializeXML and so it would not get included.
Is there some easy way to do this? I'm also hoping to make my class very easy to use so the users don't have to write a ton of code to choose SerializeXML vs. SerializePHP.
I imagine something like this:
Code:
import myService.*
var Service = new myService('server.mydomain.com', blah, blah);
// this line would result in SerializeXML being used for all data objects
// sent across the myService connection
Service.encodingMethod = 'XML';
View Replies !
View Related
How To Make Sound Optional In Flash?
I need to edit this flash design. I have not done flash in a very long time and have no clue what to do so I need a simple and step by step explanation. Currently, the flash design starts off with sound and there is an option on the bottom right corner that let's you turn it off. I need it to be the other way around. I need the flash design to start with the sound off and then have the option on the bottom right to turn it on.
How can I do this? Please explain. Thanks!
View Replies !
View Related
Create Function With Optional Parameters
Hi there! I have this simple problem...
I want to create a function that has default values for its parameters. I do it like this:
ActionScript Code:
function fn (param1:Number) {
//set the default value
if (!param1) {
param1 = 0
}
//execute the function
trace (param1)
}
I just wondered if there is a more elegant way. Something like:
ActionScript Code:
function fn (param1:Number = 0) {
trace(param1)
}
Thanks!!!
View Replies !
View Related
How To Make A Function With Optional Arguments?
I'm just starting to get into creating my own custom classes. My first experiment is a custom textfield that includes a scrollbar (and necessary behavior).
Right now the constructor function needs the height, width, a textFormat and a string (the actual text). I want to make those all optional with defaults. How would I go about doing that?
View Replies !
View Related
Creating Function With Optional Arguments Actionscript 3.0
hello
i am trying to create a function that accepts any number of optional arguments but due to the complier error checking I get
Text1137: Incorrect number of arguments. Expected no more than 3.
where as what i want to to do is pass the function any number of arguments and pull them out inside the function using the argument property
the function that call the code i have attached is as follows
callGatewayService("validateLogin", this.UserResults, this.UserFault, username, password )
Attach Code
public function callGatewayService(phpF:String, f1:Function, f2:Function){
myResultFunc = f1;
myFaultFunc = f2;
myPhpFunc = phpF;
var parameters = new Array();
var l = arguments.length
for (var i = 3; i < l; i++) {
parameters[i - 3] = arguments[i];
}
var totalParameters:Array = arguments.concat (parameters);
gateway = new RemotingConnection(gatewayURL)
gateway.call(myService+"."+myPhpFunc, new Responder(myResultFunc, myFaultFunc, totalParameters))
}
View Replies !
View Related
Get Parameter
Please...anyone who know how can I capture a parameter from the browser? Exp : <param name = variable1 value = "testing
" >
[Edited by lms11 on 11-28-2001 at 09:25 PM]
View Replies !
View Related
Parameter
please, i'm new at flash developing and need some help.
i'm using f5 and want to pass a variable from one flash file to another and read this, checking its value. thanks anyway...
View Replies !
View Related
Parameter
Hello!
I've just started to work with flash (MX) and I wonder...
How is it with parameters in flash.
If I have four scenes: start,intro,pictures,and music.
When a new visitor enter the site for the first time then I want to have an intro on every page. I have declared a boolean "introfirst=true" ---> if(introfirst){I play my intro and then setting the introfirst-parameter to false, which means next time the visitor click on the link to current page s/he wont to have to se the intro again}
What I've done is at the beginning (my startscene) I declare/set attribute to all my booleans which controlls if the visitor have entered my 4 pages. And then I change their attribute when entering current page. E.g I enter music I see the intro and the parameter "musicfirst" is set false.
But that doesn't work.
To my question is it like in java that the parameters both can be global and local. Shall I print start.introfirst or what shall i print ????
I hope you understand what I mean.
Thanks for helping me /M8M8
View Replies !
View Related
How Would I Pass A Parameter...
How would I pass a parameter (or any method) into a scrolling text box?
The parameter would come from a .jsp file. It would function exactly like an <iframe>
It would work like this.... (I run a affiliate program)
I send out an email to my clients with new links.
The problem is some 1000 of my clients have Yahoo and Hotmail accounts, and both services will replace my links with theres. So I will create a flash text box that will be independent of those meddlesome kids.
When the email is delivered it calls the flash file which in turn fills the text boxes with dyn. data. And my clients cut and paste the untouched code into there pages.
View Replies !
View Related
Parameter Passing
I have 2 swf's. Main.swf and Movie1.swf. MAIN will begin to play and then load external MOVIE1. Once MOVIE1 has played completely I would like to pass a parameter or variable to MAIN from MOVIE1. Is there a way to achieve this?
View Replies !
View Related
Parameter Passing
Hi,
I want to create a clock which will display the time at server side
for that i need to pass the time at server side as parameter to my flash file
Can i do that and how?
Waiting for response.
Thanks in Advance.
Bye
sonali
View Replies !
View Related
Parameter As Name Of A MivoeClip
I have a function that I pass parameter as a name of a movieClip in the first keyFrame.
function passname(moviename){
moviename._x+=10;
}
--
A movieClip name... girl
And another movieClip that I use to write action like this:
/*case 1.*/
onClipEvent(enterFrame){ passname(girl);}
But nothing happent. I dont know why it doent work.
If I assign Action for a button like this
/*case 2.*/
on(release){passname(girl);}
It works
Please tell me why it doesnt work in case 1?
Thanks !
View Replies !
View Related
Array In Parameter
how could i do this:
fileName_Section[0] = ["00010"]
fileName_Section[1] = ["01010", "01020"]
fileName_Section[2] = ["02010", "02020","02040", "02050"]
this is what i want:
fileNames = fileNames.concat(fileName_Section)
length = 3
fileNames = fileNames.concat(fileName_Section[0],fileName_Section[1],fileName_Section[2])
length=7
I want to find a way to make the first examples have a length of 7 also. I tried various approaches but not have worked as of yet.
View Replies !
View Related
The Play Parameter
Could someone tell me why the (param name="play" value="true" / ) causes my SWF to go crazy, and removing that line of code allows it to work?
If I set the value to False it runs fine too. Does that mean the default value for it is False? I am using the latest Flash player 6 release. Thanks
View Replies !
View Related
Passing Parameter To A Swf
Is there a way to pass parameters to a swf from the html that loads it?
and... if so, How do I get them from inside the swf?
I'm not into asking this "howto" type of questions, but my brain is to tired and time is running out for me. I have to deliver this site by tomorrow afternoon and I only need that code.
Thanks anyone who can help me...
Francisco
View Replies !
View Related
Using < And > As A Parameter In Function
I was wondering if there is a way to us the greater than and less than signs as a parameter in a function?
What I would like...
Code:
myfunction = function(equality){
if ( varX equality varY){
Do this;
}
}
and calling it...
Code:
button1.onMouseOver = function(){
myfunction(>);
}
View Replies !
View Related
Using_name As A Parameter
I trying to each this effect
function Do_This(Current_Movie)
{
Movie_Clip_Path.Current_Movie.gotoAndPlay("Close") ;
}
Do_This(this._name)
This seems really simple but it isn't working.
I am currently stuck doing this.
function do_This(Current_Movie)
{
if (Current_Movie == "something")
{
Movie_Clip_Path.Specific_Path.gotoAndPlay("Close") ;
}
if (Current_Movie == "something_else")
{
Movie_Clip_Path.Specific_Path2.gotoAndPlay("Close" );
}
}
Any Suggestions?
View Replies !
View Related
Open Asp URL With Parameter
I create an external textfile data.txt that i load
&productID0=1&image0=Master.jpg&productID1=2&image 1=Revolution.jpg&count=2&
images = new Loadvars();
images.load('data.txt');
images.onLoad = function() {
for (i=0; i<Number(images.count); i++) {
loadMovie(images['image'+i], "_root.mc"+[+i]);
}
};
I have two Movieclips called mc0 and mc1. Both they load an picture. What I want is when you click on the picture it opens an url
on (release) {
getURL("http://domain/Main.asp?ProductID="+ProductID[i], "_Blank");
}
It now gives
http://domain/Main.asp?ProductID=
It has to be
http://domain/Main.asp?ProductID=1 for the first picture and http://domain/Main.asp?ProductID=2 for the second picture
Please help me out
View Replies !
View Related
Parameter Of Function
Hi guys!!!!
I got a function like this:
function state (choice) {
_root.buttons.choice_mc.choice_selected._visible = true;
};
So, as you already have guessed, the "choice" in the setence inside the function is the parameter that enters the function. The problem is this doesn't work..i guess i have to "say" that the choise in the _root.bla bla bla is the var that enters the function!
How to do that?
Thanks a million!!!
View Replies !
View Related
StartDrag With Or Without Parameter
I wish to drag a MovieClip keeping the position of the MC (movieClip) relative to where I first clicked on it, and constrain it into a defined rectangle.
My understanding is to use the following cmd:
myMovieClip.startDrag([LOCK, [0, 0, 200, 200]]) where LOCK = 0 -- "locked to the point where the user first clicked on the movie clip (false)"
But when I click on the movieClip, the MC reposition under the mouse at its registration point. Toggling my LOCK parameter from 0 to 1 actually does not make any difference.
The only way I can start dragging - without the MC repositioning - is by using the "startDrag" method with no parameter at all:
myMovieClip.startDrag();
The problem of course, is that I now don't have any limits to where the mc can be dragged.
Any suggestion would be greatly appriciated.
Thanks in advance.
geraldine
View Replies !
View Related
Is This Possible? Action, Parameter
(Sorry bout the non-descript subject to this post)
Curious to know if this is possible:
function someFunc(var1, var2, act){
//do stuff here
--
//
if(stuff done){
act;
}
};
someFunc(100, 200, _root.gotoAndPlay(2));
The code above doesnt work (thats why i am here...), it simply runs the third parameter directly which i dont want it to, but i hope you're able to see what i'm trying to do. I want the third parameter to run when the code in the 'someFunc' is done.
I would greatly appreciate if anyone know of any solution to this problem and showed me how it done.
//edit:
I want to be able to run any sort of code in the, in this case, third parameter btw. In my real code i would for example have
this code: loadXML('xml/nyhetsbrev.xml', -4). Which is a call to another function to load an xml.
//edit
cheers
Björn
View Replies !
View Related
Transfer Any Parameter Between Two Swf?
hi developers..
i have a main.swf that where ii loadMovie Products.swf..my products.swf is full of my products pictures and all of them are buttons and have a ID..
i want to make a new swf for LoadMovie in main.swf, too that when anyone click this products.swf picture button my new swf take the ID number and call product's details which ID equal to this ID..i mean how can i transfer any parameter between two swf..
View Replies !
View Related
Passing Parameter
I have got 2 frames.
frame 1 is like this
stop()
var myScore = 0
var yourScore = 0
function makeLocalMove(myScore, yourScore){
myScore = 3
//return
trace("vv")
}
frame 2, I have got a button and set the script
on(release){
makeLocalMove(10, 5);
_root.myScore += 10
}
but there is no result coming out with the dynamic text myScore? Do anyone know where I do wrong?
View Replies !
View Related
Default Parameter Value
It seems there is a neat new feature which allows you to set default parameter values when establishing a function:
function ball (xmove:Number = 5) {
ball.x += xmove;
}
ballMove = setInterval (ball, 50);
This will move the ball. However can the default value be a variable (something like this...although as is it doesn't work):
movement = 5
function ball (xmove = movement) {
ball.x += xmove;
}
ballMove = setInterval (ball, 50);
...or is there another way to change the parameter as the ball reaches certain x locations:
if (ball.x >= 100) {
//change the direction of the ball movement (-5)
}
View Replies !
View Related
Easy For You: How To Get Parameter
Hi guys
Guess this is easy for you gurus
I call my RadarTest.swf from within a html page:
Code:
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="550" height="400" id="RadarTest" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="RadarTest.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />
<param name="testparam" value="12345">
<embed src="RadarTest.swf" width="550" height="400" align="middle" quality="high" bgcolor="#ffffff" name="RadarTest" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" testparam="12345" />
</object>
How can I retrieve the value of the parameter 'testparam' in my AS3 coding?
Thank you for helping a newbie :-)
gsub
View Replies !
View Related
|