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
Solved

Flash - convert string to object/symbol

Posted on 2011-03-22
2
547 Views
Last Modified: 2012-08-14
I've converted a symbol name to a string, slicing the last three characters of of it. Now the problem comes, I want to be able to use it again as a symbol/object.

I've got this so far, but it "ofcourse" gives warning that a String doesn't have a currentFrame.
function btnOverFunction(e:MouseEvent) {
	var thisString = e.currentTarget.name.toString();
	var currentButton = thisString.slice(0, -3);
	if(currentButton.currentFrame < 2) {
		currentButton.gotoAndPlay(1);
	}
}

Open in new window


so how can I solve this problem?
0
Comment
Question by:ErnstJacobs
2 Comments
 
LVL 17

Accepted Solution

by:
deepanjandas earned 500 total points
ID: 35190541
try this(I guess the currentButton object is within the Button):
function btnOverFunction(e:MouseEvent) {
        var currentButtonName:String = e.currentTarget.name.toString();
        currentButtonName = currentButtonName.slice(0, -3);
        var currentButtonClip:* = ( e.currentTarget ).getChildByName( currentButtonName  );//the instance name is set as what comes at currentButtonName 
        if(currentButtonClip.currentFrame < 2) {
                currentButtonClip.gotoAndPlay(1);
        }
}

Open in new window


Warm Regards
Deepanjan Das
0
 
LVL 1

Expert Comment

by:smabudhahir
ID: 35190902
Try this..

function btnOverFunction(e:MouseEvent) {
        var currentButtonName:String = e.currentTarget.name.toString();
        currentButtonName = currentButtonName.slice(0, -3);

        var nTgt = this[currentButtonName]; //Replace 'this' with the correct reference of the symbol with name as received in 'currentButtonName'

        if(nTgt.currentFrame < 2) {
                nTgt.gotoAndPlay(1);
        }
}

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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,…
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…
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 what frame rate is, how to control it and what effect it has on the video.

791 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