Solved

Flash - convert string to object/symbol

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…

746 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

11 Experts available now in Live!

Get 1:1 Help Now