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 323683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:03:13+00:00 2026-05-12T09:03:13+00:00

Should programmatic logic be inserted into an MXML Attribute? I have a few Buttons

  • 0

Should programmatic logic be inserted into an MXML Attribute? I have a few Buttons which may or may not dispatch events based on the state of related components (e.g. DataGrid or List), and I’m trying to figure out if the logic is simple enough to simply embed in one of the Event attributes in the MXML.

Here’s how I’ve been doing things:

<mx:Script>
    <![CDATA[
        private function sendEvent1():void {
            if (list.selectedIndex != -1) {
                dispatchEvent(new Event("click!"));
            }
        }
    ]]>
</mx:Script>
<mx:List id="list" dataProvider={listData} />
<mx:Button label="Click!" click="sendEvent1()" />

In this example, the ActionScript contained in the Script tag contains the logic for determining whether or not the event should be dispatched.

The Button, however, can be modified a bit, removing the need for the sendEvent1 function:

<mx:Button label="Click!" click="if (list.selectedIndex != -1) dispatchEvent(new Event("click!")" />

Ignoring some of the obvious issues in these snippets (e.g. static strings, missing code for the data provider, etc.), there are a few concerns I have with the second example:

  • The MXML is less readable (it gets long and cluttered)
  • As more function calls are required for clicking the Button, the logic in the MXML becomes much more unwieldy.
  • Embedding logic in the MXML makes it less intuitive (for me at least). If I want to know the logic of the MXML, I’m more inclined to look in the Script tag, where I expect the ActionScript.

Are there other pros behind inserting logic in an MXML attribute? I’ve been seeing this use more and more often, and I want to make sure I’m not missing any compelling reasons to change how I’ve been doing things.

  • 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. Editorial Team
    Editorial Team
    2026-05-12T09:03:13+00:00Added an answer on May 12, 2026 at 9:03 am

    I can’t think of any true benefit to adding logic to the MXML code if the code is more than one line long, like and alert or possibly at most, unconditionally setting a variable. Imagine trying to read a switch statement inline.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Let's see (in no particular order) Cursors non-sargable where clauses… May 12, 2026 at 9:03 am
  • Editorial Team
    Editorial Team added an answer You should probably include the units in the test project… May 12, 2026 at 9:03 am
  • Editorial Team
    Editorial Team added an answer PHP's socket streams have a default timeout of 60 seconds;… May 12, 2026 at 9:03 am

Related Questions

I'm currently using FORM based authentication in glassfish v2.1 to log users in and
Throughout our site there's a common model, let's say Video, that has a number
I want to generate code for creating a hash table object and assigning it
I have a DataTable which is populated from a CSV file then, using a
There are some posts about this matter, but I didn't clearly get when to

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.