Solved

Flash - convert string to object/symbol

Posted on 2011-03-22
2
542 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
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 set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

809 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