A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: PLZ HELP...Can't find the solution of this simple problem

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    7

    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.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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.

  3. #3
    Dignitary rynoe's Avatar
    Join Date
    Jan 2003
    Location
    Earth
    Posts
    760
    Stick to strict datatyping as well.
    [SIGPIC][/SIGPIC]

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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.

  5. #5
    Registered User
    Join Date
    Apr 2012
    Posts
    7
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center