Solved

indexOf problem. Whats happening here?

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to how to record live broadcast.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

688 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