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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:00:00+00:00 2026-05-26T17:00:00+00:00

I’m new to Actionscript programming. I’m trying to figure out what is the best

  • 0

I’m new to Actionscript programming. I’m trying to figure out what is the best way to return multiple variables, each having a different data type, from a function. For example, if a function needs to return variable aa ( a string) and variable bb (a number).

The function I’m using just crunches a lot of math, and doesn’t relate to an object in a GUI. One method I got from a Google search used an Object, but as (I think) this requires me to create a class, I wondered if there was a simpler way. Since an array can hold elements of different data types, perhaps this is a simpler approach (?).

Here’s an example mxml and AS3 file taken from “Flash Builder 4 and Flex 4 Bible” by David Gassner.

file: Calculator.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
  xmlns:s="library://ns.adobe.com/flex/spark" 
  xmlns:mx="library://ns.adobe.com/flex/mx" 
  xmlns:components="components.*">
  <fx:Script source="calculator.as"/>
  <s:Panel title="Calculator" horizontalCenter="0" top="20">
    <s:layout>
      <s:VerticalLayout horizontalAlign="center"/>
    </s:layout>
    <mx:Form>
      <components:ButtonTile id="input" 
        select="selectHandler(event)" 
        calculate="calculateHandler(event)"/>
      <mx:FormItem label="Entry:">
        <s:TextInput text="{currentInput}" editable="false" width="80"/>
      </mx:FormItem>
      <mx:FormItem label="Total:">
        <s:TextInput text="{currentResult}" editable="false" width="80"/>
      </mx:FormItem>   
    </mx:Form>

file: calculator.as

//ActionScript code for Calculator.mxml
[Bindable]
private var currentResult:Number=0;
[Bindable]
private var currentInput:String="";

private function calculateHandler(event:Event):void
{
  currentResult += Number(currentInput);
  currentInput="";
}
private function selectHandler(event:TextEvent):void
{
  currentInput += event.text;
}

Could someone illustrate how to modify one of the functions in calculator.as, just as an example how to return two values, where one is a number and the other a string? Is there an obvious best-way to do this, or, what would be the pros/cons of different approaches? Thanks in advance!

  • 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-26T17:00:01+00:00Added an answer on May 26, 2026 at 5:00 pm

    You could just simply return an Object which is dynamic and thus lets you define values on the fly, like this:

    return {something: "string", another: 18};
    

    Or:

    var obj:Object = {};
    
    obj.something = "string";
    obj.another = 18;
    
    return obj;
    

    But in my opinion this is really poor practice (especially if your function is to return the same sets of information with new values).

    I’d take this route:

    You can create your own class that holds various properties. From there you can return an instance of this object with the properties defined as you wish.

    Example:
    This would be in an external file called CollisionData.as

    package
    {
        public class CollisionData
        {
            public var x:Number = 0;       // X coordinate of the collision
            public var y:Number = 0;       // Y coordinate of the collision
            public var angle:Number = 0;   // Collision angle
        }
    }
    

    And your function could be:

    function calculate():CollisionData
    {
        var col:CollisionData = new CollisionData();
    
        // determine collision details
        col.x = 115;
        col.y = 62;
        col.angle = 0.345;
    
        return col;
    }
    

    Then you can create your own collision data based off the result:

    var myCollision:CollisionData = calculate();
    

    And fetch the details:

    trace(
        myCollision.x,
        myCollision.y,
        myCollision.angle
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

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.