Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Slice Function 2

Status
Not open for further replies.
Dec 24, 2001
857
GB
I have a function with a loop which creates (attaches) some textAreas and at the end of the loop I have it create an onRelease function for whatever textArea was created. The onRelease function calls another function (called displayInfo) and passes 'this' and another variable. When I trace both these variables in the displayInfo function it shows up fine - it has the correct information.

Now if I try to slice the 'this' variable (which is now stored in textAreaName) it just returns it as undefined even though it works fine for the other variable which was passed. When I trace textAreaName, it shows up fine as _level0.movieClipName.textArea0 (or 1 or 2 etc depending on what they click on) but trying to slice it doesn't work. Does anyone know why this is?

I'm probably not being very clear so if you need more info let me know!
 
Heya renowned,

I guess it depends what you want to do with the 'this' variable. Make sure you are aware of your data types. If 'this' is an object, it won't slice. Slice is method for handling [blue]Array[/blue] data. If you want to break it apart into an array (from a string), you might want to use [blue]split( [/blue][green][delimiter][/green] , [green][limit][/green][blue] )[/blue].



Hope that helps!
pf

"If you build it....it won't work the first time.....or the second ;)
 
If I understood you correctly, you are assigning "this" to a variable. But "this" is a reference to the current Object. You cannot "slice()" Object, you can only "slice()" either String or Array.

What you need to do is, instead of assign "this" to the variable, assign either "this._name" or "String(this)". Then you can perform any String operations such as "slice()".

If you use "this", you get the Object: [tt]_level0.MovieClipName.textArea0[/tt]
If you use "this._name", you get the name of the Object as a String: [tt]"textArea0"[/tt]
If you use "String(this)", you get the Object reference as a String: [tt]"_level0.MovieClipName.textArea0"[/tt]

Hope this makes sense.

Kenneth Kawamoto
 
Good call Kenneth,

How did I overlook String.slice()? :p

Renowned, you can use the typeof() function to determine what kind of datatype you're dealing with.

Cheers!
pf

"If you build it....it won't work the first time.....or the second ;)
 
>you can use the typeof() function to determine what kind of datatype you're dealing with

Or use ActionScript 2 with strict data typing - it eliminates datatype mismatch completely.

Kenneth Kawamoto
 
Hi Paul / Kenneth,

Thanks for the good explanation - at least now I know why it wouldn't slice 'this'! (Well actually, I wasn't trying to slice 'this', I was trying to slice something which was set to the same thing as 'this' but obviously its the same outcome)

I've gone for the 'this._name' option since its simple and does precisely what I need. Basically what I was trying to do was work out what number the current textArea is because they're created dynamically with their number added to the end of the name, but I couldn't use the 'i' variable which gave them the number (as in for (i=0)...) because it was always set to the last number...

Anyway, all sorted now so thanks again for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top