Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

indexOf problem. Whats happening here?

Posted on 2003-11-09
3
Medium Priority
?
170 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

Industry Leaders: 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

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
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.

596 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