-
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
;-)
-
Dignitary
comment is a reserved word that is used only for commenting on code
-
Originally Posted by rynoe
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....
???
-
Dignitary
the length function works on arrays and strings
-
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.
;-)
-
Dignitary
Sounds like a possibility, I don't see all the code so can't tell.
var bar:String = foo.toString();
-
FK'n_dog
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 > 0 && _loc4._comment.length < 60) {
trace("<60");
} else {
trace(">60");
}
};
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|