Solved

indexOf problem. Whats happening here?

Posted on 2003-11-09
3
163 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
3 Comments
 
LVL 5

Accepted Solution

by:
Calron earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now