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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to parse string but not literal string...

Status
Not open for further replies.

fedtrain

Instructor
Jun 23, 2004
142
US
Once again I have run into something....

Here is the start of the code:
Code:
var target = this.onStage.allNotesOnStage.easyArray
var randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
var showNote = target[randomNum];

This is an example of what showNote turns out to be....
_level0.onStage.allNotesOnStage.a2Note

This is what I want to do with that result, but it doesn't work:
Code:
var noteString:String = showNote
var findNote:Array = noteString.split (".")
trace (findNote)

findNote comes up as undefined.

So, out of 'showNote', I really only need the very last bit of the string that gets fed to it.

Thanks
Dave



"Credit belongs to the man who is actually in the arena - T.Roosevelt
 
if the very last bit all that you want then something like

var target = this.onStage.allNotesOnStage.easyArray
var randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
var showNote = target[randomNum];
var findNote:Array = showNote.split (".")
trace (findNote[findNote.length-1])

 
Thanks for the suggestion, but that doesn't seem to work either. I have continued to putz around on this....

The array I am calling from (which is two movies deep) looks like this:
Code:
var easyArray:Array = new Array (f3Note, g2Note,a2Note, b2Note, c2Note, d2Note, e2Note)

Now it has to look like that to make some other functionallity work. (This was all on a post here some time back.)

In an experiment I decided to change that array to this:
Code:
var easyArray:Array = new Array ("f3Note", "g2Note","a2Note", "b2Note", "c2Note", "d2Note", "e2Note")

Once I did that the original function quit, but this function was able to find the easyArray[] part with no issues.

Problem is that I need both functions. So I am currently trying to figure out how to get this thing into a string, that can be parsed...and then get the last bit out. This has been a long day.

So...any more ideas?

"Credit belongs to the man who is actually in the arena - T.Roosevelt
 
OK....here's my (extremely) convoluted solution. (Part of it comes from the "Ah ha!" that Bill made me think of)

[Beware sentence ending in preposition.]

Code:
//this takes the data from above and converts to string so that note name can be pulled out
var targetArray = target.toString()
var noteArray = targetArray.split (",")
var noteString = noteArray [randomNum]
var noteStringItems = noteString.split(".")
var actualNote = noteStringItems[noteStringItems.length-1]
trace ([actualNote])[

Now I can use 'actualNote' as a name to call on other things in the function...such as complete a text field, and find another object related to that name.

Yay me....

Can anyone tell me if there is a way to avoid all this spaghetti code? Was there a faster way to get this?

Later
Dave

"Credit belongs to the man who is actually in the arena - T.Roosevelt
 
spaghetti code?

yes it can a problem

the code you have could probably reduced to a few lines of actionscript

i have stopped writing timeline code as much as possible and just use class files

depends on your programming background but its it all so much easier and more maintainable with class files


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top