2
I’m having a problem with parameters for my function. It’s not getting the parameter I pass to it. Follow the code below:
function gerarescala(e:MouseEvent):void
{
var tom:String = texto.text;
var escala:Array = new Array('C','C#','Db', ...);
var container:Array = new Array([vazio]); //Este array vai receber elementos de acordo com os elementos do array escala.
var pesquisa,i:Number;
[Aqui vai o Código preenchendo o array container] ...
[A função "imp", é muito extensa, então esse é só um trecho, mas é a mesma coisa em toda a função]
function imp(pos:String):String {
var retorno:String;
if (pesquisa == 1)
{
if (pos == "D#")
{
retorno = container[3];
}
else if (pos == "F")
{
retorno = container[6];
}
return retorno;
}//fim func imp
}//Fim func grarescala
In the course of the code I want to do, I will call the function as follows: imp(container[3]); passing an element of the container array to my function, but I tested it and when I run it I see that it turns me "null". I have already checked with direct "string" entries and it worked, it just doesn’t work with this array parameter that I pass to it. The rest of the code is all working and everything is fine, the only thing that is giving problem is with the parameter.
I noticed that the imp function is not seeing the container array, and I’ve put the imp function outside the main function, but if I do this the imp function will not see any variables, and if I take the main function variables it will not work the way I want it to.
Any suggestions ??
Is there a way to put the complete code somewhere? (e.g., Pastebin) Just looking at the piece you posted can’t identify where the problem might be...
– mgibsonbr
@mgibsonbr As I said the function "imp()" is very extensive. The following code would be:
– FenixDK
just calling the function seven times, printing on the screen. imp(container[3] ... imp(container[6] ... imp(container[7] ... container[10] on. As I said the real problem is the parameter I pass to function, and it happens with the array element parameter[];
– FenixDK
I’m not talking about putting the full code here, but to post it somewhere (Pastebin, ideone, etc) and put the link here. You states that the problem is in passing parameter, but how can we be sure (and help you) if we do not know your code?
– mgibsonbr
I’d like to help you @Fenixdk, but I don’t understand any of your code, post the code somewhere or edit your question to make it more understandable.
– bio
@mgibsonbr, Good sorry for the confusion, the entire code is here: http://pastebin.com/R4Uj1Ra8
– FenixDK
Blz, now it’s clearer, +1. As for the call from
imp
, Do you have an example of what works and what doesn’t? For example, iftom
(texto.text
) for "C#",imp("D#")
returns"D#"
andimp(container[3])
returnsnull
. That’s it?– mgibsonbr
What happens in this code is: tone is a user input, and from there the container array will be filled according to this entry. the check pattern, which will go through the function and be analyzed is some elements of the container, eg: imp(container[3]); according to what is in the container[3] the imp() function will return me according to what I want. Only that the function imp() works according to the variable "search" but it is not accessing this variable as well as the container array.
– FenixDK
@mgibsonbr while your question of what works, the only thing that is not working is that part of the parameter as array[]. How direct string works ex: imp("D"). I have tested with some "trace". but imp() returns me null when I pass it as array[].
– FenixDK
I find it unlikely, because as far as I know Actionscript deals correctly with closures. Anyway, a suggestion: how about defining
imp
so that she receivespesquisa
andcontainer
as additional parameters, instead of accessing these variables from the external scope? See if this helps at all. Personally, I’m "betting" on a logic error instead, but I’m not sure. Note for example that not every input produces a non-zero answer, and that there are certain repeated indices - such asC
andC#
, both1
- and others that seem incorrect, likeD#
,5
.– mgibsonbr
In this part, I think there are no errors because this code is the same as PHP. As for the indexes I will check an optimization.
– FenixDK
I was testing something here in the code, and I found out that the container has a problem even though it’s filled in. var var1:String = container[3]; I declared this variable to test and when I print it, it returns "null". can tell me if the error can be array manipulation ?
– FenixDK
@Fenixdk From what I saw in your code, the creation of
container
seems to be correct.escala
is working? I noticed the arraycontainer
is unnecessary (although useful) - you can replacecontainer[i]
forescala[(i + pesquisa) % 17]
for anyi
. Since of coursepesquisa
has a valid value. (By the way, have you checked this? I don’t know Actionscript very well, the onlyindexOf
I know is to look for a substring inside a string. It works with arrays too?)– mgibsonbr
Yes, "indexof" works like a PHP "array_search"
– FenixDK
It is not necessary to take into account the checking of entries now. I will have no problem with that.
– FenixDK