Copy link to clipboard
Copied
i also has another problem here is the senario .first i select the square (there are too many object one of is square )then click the button now my event target is button previous one is square so i need to change the square(object) using that button.
1 Correct answer
Create a variable and assign it a class designation to agree with whatever the square is (MovieClip?).
var squareMC:Movieclip;
Then, when the square is clicked, assign the evt.currentTarget to that variable...
squareMC = MovieClip(evt.currentTarget);
Then your button event handler code should be able to use squareMC to target the square.
Copy link to clipboard
Copied
Create a variable and assign it a class designation to agree with whatever the square is (MovieClip?).
var squareMC:Movieclip;
Then, when the square is clicked, assign the evt.currentTarget to that variable...
squareMC = MovieClip(evt.currentTarget);
Then your button event handler code should be able to use squareMC to target the square.
Copy link to clipboard
Copied
thank you for answering my question but i have to create that variable inside the function then i cannot access that variable when i'm in another function so how i deal this.(i have not much knowledge about flash script so please explain in simple way ).
Copy link to clipboard
Copied
Declare the variable outside the function so that it will be available to any function. Assign a value to the variable inside whichever function does that.
Copy link to clipboard
Copied
thanks a lot. it is now work.
Copy link to clipboard
Copied
Hi thenaa
I tried with it. how you able to work it, because when
I declare variable outside the function but , As3 is taking it as two different variables. here is my code
var m:MovieClip = new MovieClip();
var mc:my_mc = new my_mc();
addChild(mc);
mc.addEventListener(MouseEvent.CLICK, onC);
function onC(e:MouseEvent)
{
m= e.target as MovieClip;
trace(m.name);// on click it provides instance1
}
trace(m.name)// it provides instance2
Copy link to clipboard
Copied
Hi thenaa
I tried with it. how you able to work it, because when
I declare variable outside the function but , As3 is taking it as two different variables. here is my code
var m:MovieClip = new MovieClip();
var mc:my_mc = new my_mc();
addChild(mc);
mc.addEventListener(MouseEvent.CLICK, onC);
function onC(e:MouseEvent)
{
m= e.target as MovieClip;
trace(m.name);// on click it provides instance1
}
trace(m.name)// it provides instance2
Copy link to clipboard
Copied
hI NED, i was just surfing these fourms, i tried it
I declare variable outside the function but , As3 is taking it as two different variables. here is my code
var m:MovieClip = new MovieClip();
var mc:my_mc = new my_mc();
addChild(mc);
mc.addEventListener(MouseEvent.CLICK, onC);
function onC(e:MouseEvent)
{
m= e.target as MovieClip;
trace(m.name);// on click it provides instance1
}
trace(m.name)// it provides instance2
Copy link to clipboard
Copied
The first two lines of your code create two different objects, which Flash automatically names as instance1 and instance2. When you assign m to be a reference to mc it will display mc's name instead of the name it started with.
Copy link to clipboard
Copied
yes,
right but what if i want to
access m outside funciton, i am not able to do that. as you told that declaring variable outside function, so we can use it in another function, but i am not able to do that. can you provide me a simple script in which i can get the name of clicked movieclip outside event listener method. Looking forward to hear from you soon.
Thanks,
Gaurav S.
Copy link to clipboard
Copied
Your code does access m both inside and outside the function. I don't know how else to explain it to you except to tell you to look at your own code.

