Solved

indexOf problem. Whats happening here?

Posted on 2003-11-09
3
164 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

912 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

17 Experts available now in Live!

Get 1:1 Help Now