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

  • Home
  • SEARCH
  • 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 141647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:48:37+00:00 2026-05-11T07:48:37+00:00

Data binding in ActionScript is really cool. But what if I want to refactor

  • 0

Data binding in ActionScript is really cool. But what if I want to refactor a big switch or if statement inside the curly braces into a function, for example:

 {person.gender == 'male' ? 'Mr.' : 'Ms.'} 

into:

 {salutation(person)} 

The compiler doesn’t let me do that. I know about properties and I could write getters and setters on the person object. But since I am using inlined JSON objects now that’s not convenient(I think). What are other good ways to refactor this code?

To answer Matt’s comment. The data type of person is just plain Object. It was decoded from JSON format coming from a service call.

  • 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-11T07:48:37+00:00Added an answer on May 11, 2026 at 7:48 am

    You’ll need to make the Person class (assuming you have one) bindable in order for this to work.

    However, since you are saying you’re using JSON objects, I’m assuming you just have anonymous objects that were parsed from a JSON string. In that case, I’m pretty sure that won’t work. You’ll need to create a strongly typed object that has bindable properties.

    Just FYI: to avoid having to write custom JSON parsers for every object you want to create, you can create strong typed objects from vanilla objects using a bytearray trick:

    public static function toInstance( object:Object, clazz:Class ):* {   var bytes:ByteArray = new ByteArray();   bytes.objectEncoding = ObjectEncoding.AMF0;    // Find the objects and byetArray.writeObject them, adding in the   // class configuration variable name -- essentially, we're constructing   // and AMF packet here that contains the class information so that   // we can simplly byteArray.readObject the sucker for the translation    // Write out the bytes of the original object   var objBytes:ByteArray = new ByteArray();   objBytes.objectEncoding = ObjectEncoding.AMF0;   objBytes.writeObject( object );    // Register all of the classes so they can be decoded via AMF   var typeInfo:XML = describeType( clazz );   var fullyQualifiedName:String = typeInfo.@name.toString().replace( /::/, '.' );   registerClassAlias( fullyQualifiedName, clazz );    // Write the new object information starting with the class information   var len:int = fullyQualifiedName.length;   bytes.writeByte( 0x10 );  // 0x10 is AMF0 for 'typed object (class instance)'   bytes.writeUTF( fullyQualifiedName );   // After the class name is set up, write the rest of the object   bytes.writeBytes( objBytes, 1 );    // Read in the object with the class property added and return that   bytes.position = 0;    // This generates some ReferenceErrors of the object being passed in   // has properties that aren't in the class instance, and generates TypeErrors   // when property values cannot be converted to correct values (such as false   // being the value, when it needs to be a Date instead).  However, these   // errors are not thrown at runtime (and only appear in trace ouput when   // debugging), so a try/catch block isn't necessary.  I'm not sure if this   // classifies as a bug or not... but I wanted to explain why if you debug   // you might seem some TypeError or ReferenceError items appear.   var result:* = bytes.readObject();   return result; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 67k
  • Answers 67k
  • 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
  • added an answer While I've not done any GLE work specifically, I can… May 11, 2026 at 11:52 am
  • added an answer It sounds like you are trying to access variables declared… May 11, 2026 at 11:52 am
  • added an answer TransactedInstaller will call Commit/Rollback automaticly if the custom action has… May 11, 2026 at 11:52 am

Related Questions

I'm trying to do a Data Binding in the C# code behind rather than
I need to define new UI Elements as well as data binding in code
I'm working through the Data Binding chapter in Pro WPF in C# 2008. They
I have a very simple WPF application in which I am using data binding
In ASP.NET, I am exporting some data to Excel by simply binding a DataSet
I am trying set up databinding as described in the title. The problem I
I would like to use databinding when displaying data in a TextBox. I'm basically
In WPF: Can someone please explain the relationship between DependencyProperty and Databinding? I have
I've a form and I'm doing databinding of my datagridview in the event form
Problem: Customer X has requested that pages using XML DataBinding and Databound tables in

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.