Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 97357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:59:22+00:00 2026-05-10T23:59:22+00:00

This question doesn’t relate only to MouseEvent.CLICK event type but to all event types

  • 0

This question doesn’t relate only to MouseEvent.CLICK event type but to all event types that already exist in AS3. I read a lot about custom events but until now I couldn’t figure it out how to do what I want to do. I’m going to try to explain, I hope you understand:

Here is a illustration of my situation:

for(var i:Number; i < 10; i++){     var someVar = i;      myClips[i].addEventListener(MouseEvent.CLICK, doSomething); }  function doSomething(e:MouseEvent){ /* */ } 

But I want to be able to pass someVar as a parameter to doSomething. So I tried this:

for(var i:Number; i < 10; i++){      var someVar = i;     myClips[i].addEventListener(MouseEvent.CLICK, function(){         doSomething(someVar);     }); }  function doSomething(index){ trace(index); } 

This kind of works but not as I expect. Due to the function closures, when the MouseEvent.CLICK events are actually fired the for loop is already over and someVar is holding the last value, the number 9 in the example. So every click in each movie clip will call doSomething passing 9 as the parameter. And it’s not what I want.

I thought that creating a custom event should work, but then I couldn’t find a way to fire a custom event when the MouseEvent.CLICK event is fired and pass the parameter to it. Now I don’t know if it is the right answer.

What should I do and how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:59:22+00:00Added an answer on May 10, 2026 at 11:59 pm

    Without knowing more about your application, it seems more like you should use the target to pass parameters, or extend MouseEvent. The former would be more in line with common practice, though. So for example, if you exposed an integer public property on your ‘clip’ object (whatever it is):

    public class MyClip {    public var myPublicProperty:int;     public function MyClip() { //... } }  for (var i:int = 0; i < 10; i++) {    myClips[i].myPublicProperty = i;    myClips[i].addEventListener(MouseEvent.CLICK, doSomething); } 

    … and then, in your event listener, you could retrieve that property using either the target or currentTarget property of the event (probably currentTarget, in your case):

    function doSomething(event:MouseEvent):void {    trace(event.currentTarget.myPublicProperty.toString()); } 

    That ought to do it! Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 313k
  • Answers 313k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here is a stab in the dark: If you can… May 13, 2026 at 10:43 pm
  • Editorial Team
    Editorial Team added an answer Try this: User.find_or_create_by_name(:name=>'ceilingfish', :email => 'an_email@a.domain', :legs => true, :face… May 13, 2026 at 10:43 pm
  • Editorial Team
    Editorial Team added an answer My suggestion is: Use RabbitMQ with XMPP adaptor. Use Python… May 13, 2026 at 10:43 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I've got a string that has curly quotes in it. I'd like to replace
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.