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

Related Questions

This post asks this question but doesn't really give an answer, so I thought
This seems like a basic question, but it's still bugging me. Why doesn't MyObject
This should be a very basic design question, but for some reason it doesn't
I have a question about locking. This doesn't have to be only about record
First of all, I am sorry if this question doesn't belong to SO since
my apologies if this question doesn't make much sense, but I'm new(ish) to Actionscript,
I'm surprised that this question apparently doesn't yet exist. If it does, please help
I have read this question but it doesn't exactly answer my question. Unfortunately, it
I did see this question but it doesn't fully answer the question I have.
(Hope this doesn't get duplicated; second attempt at submitting this question) I'm working on

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.