A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] 1067: Implicit coercion of a value of type Number to an unrelated type String.

  1. #1
    Member
    Join Date
    Nov 2004
    Location
    Michigan, USA
    Posts
    41

    resolved [RESOLVED] 1067: Implicit coercion of a value of type Number to an unrelated type String.

    I searched the forum for an answer to this error, but couldn't find one. I am new to AS3 and am doing exercises in a textbook for CS3. I am doing the exercise exactly as it describes in the book, but I keep getting the error, "1067: Implicit coercion of a value of type Number to an unrelated type String."

    My code looks like this (and yes, the instance name for the dynamic text box matches what I have written in the code):

    Actionscript Code:
    var myDate:Date = new Date();
    myTextField_txt.text = myDate.getDate();

    Seems very simple, right? All I want it to do is display the current date in this dynamic text field. This is exactly how the book tells me to write the code. I think the book may be wrong. I tried the same exercise using AS2 and it worked fine.

    I e-mailed my instructor about this on Wednesday (it is for an advanced Flash course through eclasses.org) and haven't heard back yet, so it is a bit frustrating.

    Thanks.
    Last edited by jillesreina; 01-23-2011 at 12:06 PM.

  2. #2
    Senior Member
    Join Date
    Jan 2009
    Posts
    208
    myTextField_txt.text = String(myDate.getDate());

  3. #3
    Member
    Join Date
    Nov 2004
    Location
    Michigan, USA
    Posts
    41
    Thank you!!

  4. #4
    Junior Member
    Join Date
    May 2013
    Posts
    1

    Same question,

    im trying to add a score to my mix

    here's my equation

    var score:Number = 0;

    if(bball1_mc.y >= 447.2){
    bball1_mc.y = -71.8;
    bball1_mc.x = randy;
    score = score+10;
    run = true;
    }

    score_txt.text = String(score());

    it doesnt seem to work, some help would be nice

  5. #5
    Junior Member
    Join Date
    Nov 2015
    Posts
    7
    Quote Originally Posted by bossross View Post
    im trying to add a score to my mix

    here's my equation

    var score:Number = 0;

    if(bball1_mc.y >= 447.2){
    bball1_mc.y = -71.8;
    bball1_mc.x = randy;
    score = score+10;
    run = true;
    }

    score_txt.text = String(score());

    it doesnt seem to work, some help would be nice
    Try this for your last line instead:

    score_txt.text = String(score)

    The reason for this is that the solution to the OP's problem: myTextField_txt.text = String(myDate.getDate()); - the brackets in bold are because the .getDate part of the line is referring to a function, which is typically followed by () afterwards. For your own score, it is simply a variable and not a function which does not need the additional brackets.

    I understand this is probably a little late for you given the age of the post, but perhaps this may be of help to someone else who finds this post in the future

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