?
Solved

indexOf problem. Whats happening here?

Posted on 2003-11-09
3
Medium Priority
?
169 Views
Last Modified: 2012-06-27
This one is driving me crazy!

Here is an example:

var test = "test.string";
var charPos = test.indexOf(".");
trace(charPos);

This works on my copy of Flash MX 2004 professional and Flash MX. I get 4 returned for charPos.

Now say I put this code inside an onPress event in a button called b1 and use eval to get the path... like this or just use 'this'

var test = eval(this.b1);   //  OR var test = this;
trace(test);  // returns _level0.b1
var charPos = test.indexOf(".");
trace(charPos);   // returns nothing!

the trace command gives the correct path for test but charPos does not give any output!

Am I going crazy? What is happening here?

Isis


0
Comment
Question by:isis071598
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Accepted Solution

by:
Calron earned 2000 total points
ID: 9712816
I think your problem is that this.b1 is of type movieclip. You have to conver it to a string.
try this:

var test = String(this.b1);

That should do the trick.
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 9712827
or

on (press) {
      var test = eval(this.b1);
      //  OR var test = this;
      trace(test);
      // returns _level0.b1
      var charPos = String(test).indexOf(".");
      trace(charPos add "Char");
      // returns nothing!
}
0
 
LVL 1

Author Comment

by:isis071598
ID: 9713088
Calron  THANK YOU!!!!
I didn't know that you could use a cast in actionscript. I was thinking later that the assignment could be a reference not a value. I am a new actionscript user coming from Delphi so I am still finding my feet.

Thank you again!

Isis
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to how to record live broadcast.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question