A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Can you spot the mistake in this... I can't!

  1. #1
    Member
    Join Date
    Jul 2009
    Posts
    43

    Can you spot the mistake in this... I can't!

    Hi all,

    I'm trying to do a test on the length of a string and then call a function depending on the result. This is the pertinent excerpt from the fla file:

    Code:
            
    _loc4._comment = candles[_loc3].comment;
    // I want to find out the length of _comment and call differently depending
    
            _loc4.onRollOver = function ()
            {
    
    	if (_loc4._comment.length > 0 && _loc4._comment.length < 60) {	
    show_comment(this._comment, this._x + this._parent._x, this._parent._parent._y - 50);
    } else {
    show_comment(this._comment, this._x + this._parent._x, this._parent._parent._y - 100);
    }
    			
    				
                
            };
    Basically I want to check the length (in characters) of _loc4.comment and if its under 60 call with an offset of 50 and if its not call with an offset of 100.

    Can someone point out where I'm going wrong? I've been struggling with this all afternoon and its driving me nuts!

    Many thanks

    ;-)

  2. #2
    Dignitary rynoe's Avatar
    Join Date
    Jan 2003
    Location
    Earth
    Posts
    760
    comment is a reserved word that is used only for commenting on code
    [SIGPIC][/SIGPIC]

  3. #3
    Member
    Join Date
    Jul 2009
    Posts
    43
    Quote Originally Posted by rynoe View Post
    comment is a reserved word that is used only for commenting on code
    Hi Rynoe,

    Thanks for your input.

    The strange thing is the following code works perfectly...

    Code:
            
    _loc4._comment = candles[_loc3].comment;
    
    
            _loc4.onRollOver = function ()
            {
    
    show_comment(this._comment, this._x + this._parent._x, this._parent._parent._y - 50);	
    				
                
            };
    I think it must be something to do with the way I'm trying to ascertain the length or do the comparison but I can't see what the problem is.

    I'm brand new to actionscript so it could be something really really simple but I can't see it....

    ???

  4. #4
    Dignitary rynoe's Avatar
    Join Date
    Jan 2003
    Location
    Earth
    Posts
    760
    the length function works on arrays and strings
    [SIGPIC][/SIGPIC]

  5. #5
    Member
    Join Date
    Jul 2009
    Posts
    43
    I think _loc4._comment is a string. It is text that originates from an xml script and gets passed to the Flash file.

    Is there anything I need to do to _loc4._comment to ensure its a string?

    Thanks for your continued help.

    ;-)

  6. #6
    Dignitary rynoe's Avatar
    Join Date
    Jan 2003
    Location
    Earth
    Posts
    760
    Sounds like a possibility, I don't see all the code so can't tell.

    var bar:String = foo.toString();
    [SIGPIC][/SIGPIC]

  7. #7
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    what do the traces reveal ?

    PHP Code:
    trace(candles[_loc3].comment);
    _loc4._comment candles[_loc3].comment;
    trace(_loc4._comment+" - "+typeof _loc4._comment);


    _loc4.onRollOver = function (){
    trace(_loc4._comment.length);
    if (
    _loc4._comment.length && _loc4._comment.length 60) {    
    trace("<60");
    } else {
    trace(">60");
    }
    }; 

  8. #8
    Member
    Join Date
    Jul 2009
    Posts
    43
    Thanks Rynoe,

    Doing the toString() worked. My if/else is evaluating correctly now.

    a_m_d,

    Thanks for your input. I'll have a look at the trace output just out of interest (and in the interests of furthering my very very limited knowledge).

    A big big BIG thank you to both of you for all your help.

    It is much appreciated.

    ;-)

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