-
PLZ HELP...Can't find the solution of this simple problem
Actionscript Code:
var choice1:String;
function replayNew(event:MouseEvent):void {
if(add1+add2+add3==3) { MovieClip(this.root).gotoAndPlay("finish"); }
randomChoice(); function randomChoice() {
var selectOne:Array=[L1,L2,L3];
choice1= selectOne[getRandomNumber(0,selectOne.length-1)]; [B] trace(selectOne[getRandomNumber(0,selectOne.length-1)]
trace("RANDOM CHOICE IS :" + choice1);[/B]
function getRandomNumber(min:Number,max:Number):Number
{
var randomNumber:Number=Math.round(Math.random()*(max-min)+min);
trace("FIRST TRACE"+randomNumber);
return randomNumber;
} }
My problem is
trace(selectOne[getRandomNumber(0,selectOne.length-1)]) and
trace("RANDOM CHOICE IS :" + choice1) is giving NULL...
also the trace statement before return randomNumber; is also giving two results
The overall result is
FIRST TRACE2
FIRST TRACE1
null
RANDOM CHOICE IS :null
I am not able to understand why,when choice1 variable is also a string.
Plz help me.
-
The things in your array (L1, L2, L3) are probably null. Did you ever initialize them?
And of course you get two traces from getRandomNumber. You call it twice. Once in the line which sets choice1, and then again in the trace line immediately following.
-
Dignitary
Stick to strict datatyping as well.
-
I whole-heartedly agree that strict typing is strictly better than dynamic typing. But where wasn't he using it, other than randomchoice lacking a :void return?
As long as we're nitpicking, he's also got named nested functions, for no particular reason. The code would be much cleaner and easier to understand with those unnested. The indentation follows no discernable rules, and is generally absent. And he's missed at least one closing brace in the pasted code. He's inconsistent with statement ending semicolons, too.
None of that was relevant to why it didn't operate as he expected.
-
Problem has been solved.Thankyou so much.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|