Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to store event.target to variable

New Here ,
May 04, 2010 May 04, 2010

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.

TOPICS
ActionScript
3.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 04, 2010 May 04, 2010

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.

Translate
LEGEND ,
May 04, 2010 May 04, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 09, 2010 May 09, 2010

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 ).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 10, 2010 May 10, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 12, 2010 May 12, 2010

thanks a lot. it is now work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 12, 2010 May 12, 2010

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

please guide in this

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 12, 2010 May 12, 2010

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

please guide in this
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 12, 2010 May 12, 2010

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

please guide in this

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 12, 2010 May 12, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 12, 2010 May 12, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 12, 2010 May 12, 2010
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines