A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: What's wrong with this code? Array error

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    16

    What's wrong with this code? Array error

    Actionscript Code:
    text_field.addEventListener(Event.ENTER_FRAME, fl_AnimateHorizontally);

    function fl_AnimateHorizontally(event:Event)
    {
       
    45  var txt_colors:Array=new Array("black", "purple", "grey", "beige")
    46   text_field.color=txt_colors[Math.random(3)];


    What I want to do is have a text strip (text_field) take on random colors contained in the txt_colors array, obviously, upon ENTER_FRAME.

    But I keep getting the following error msg:

    "Scene 1, Layer 'Actions', Frame 1, Line 46 1137: Incorrect number of arguments. Expected no more than 0."




    Incorrect number of arguments? I can't see where, since Math.random is supposed to take 1 argument, correct, and it has to be a number, which it is?



    Thanks for any help.

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    You have to use textColor to give your textfield a different color, and you can't define the colors in english - you have to do it in hex codes, for example, red is, 0xFF0000 - simply go to a site like ColorPicker, choose the colors you want, copy their hex codes, add 0x in front of the copied hex codes, and you have a Flash Color Hex Code

    Example:

    Let's say I want the colors red, black and green. I go to ColorPicker website, slide to what kind of colors I want, for instance, red, which is, FF0000, then I copy the Hex code on the small textfield above the color palette, add 0x to my hex code, giving me a Flash Hex color code, 0xFF0000 - and then do the same with the other colors, and add them in my array, and choose a random value, which I have to round to an integer, so this would be the code inside the function:

    Actionscript Code:
    var txt_colors:Array = new Array("0xFF0000", "0x000000", "0x00FF00");
    var random_value = Math.round(Math.random()*txt_colors.length);
    txt.textColor = txt_colors[random_value];
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    16
    Hey buddy, the 16 year old Flash master

    I think I've never seen someone explain code howtos as clearly as you do impeccable. And the answer came fast too, which is great.

    I'm going to immediately try your suggestion, and come back with the result.

  4. #4
    Junior Member
    Join Date
    Nov 2011
    Posts
    16
    Ok, the previous error message is now gone. But instead I'm getting the following output message:

    "Fonts should be embedded for any text that may be edited at runtime, other than text with the "Use Device Fonts" setting. Use the Text > Font Embedding command to embed fonts."

    The text is animated btw (it's the same as in my last question if anyone recalls). I selected that text, and then selected embed font from the text menu. Well, the text doesn't change colors, so I must be missing something. Maybe I don't know how to embed fonts?

  5. #5
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Maybe provide the FLA file?

    also, did you change my code in AS2 to AS3? Just wondering :P
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  6. #6
    Junior Member
    Join Date
    Nov 2011
    Posts
    16
    Were you using Actionscript 2.0? I didn't know. All I know is I'm working in an AS 3.0 document. I don't want to make the fla public, though I wouldn't mind if it was just us two around. But you know what, I'll just search google for the last question, as it's pretty generic, and come back with the answer if I find it.

  7. #7
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Well, that's too bad, but all right

    to embed font, simply select your textfield, click on the Embed... button in the Properties Panel, select/check/tick, Uppercase, Lowercase, Numerals and Punctuations, and press OK!
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

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