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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:55:27+00:00 2026-05-26T22:55:27+00:00

I’m building a mobile AIR app using Flash Builder 4.5. The initial view in

  • 0

I’m building a mobile AIR app using Flash Builder 4.5. The initial view in my views package is TestHomeView.mxml. I want to refer to it in one of my .as classes elsewhere in the app, and I’m not sure how to do that.

Theoretically I should be able to add an “id” attribute to TestHomeView.mxml, but FB gives me an error: “id is not allowed on the root tag of a component”. The root tag is s:view.

The reason I need to do this is that within another class I make various calculations and then need to pass an array of values to a component in my view class. So in SomeOtherActionScriptClass.as I first assemble the array, myArray, and then in that class I want to do this:

 myViewComponent.viewArray = myArray;

If I’m going to do that, I also need to import the view class into the .as class, which strikes me as weird. So is there a simple way to do what I want, or do I have to dispatch a custom event which contains the array, and listen for it in the view class?

EDIT – Based on the below MVC suggestion I did the following in model:

    [Bindable]
public class Model
    {
    private static var myModel:Model;//doesn't let me name it 'model' because
                                     //I have a package named 'model'
    public var myArray:Array;  //its value set later in model code
public function Model()
{
    if ( Model.myModel != null ){
        throw new Error( "Only one Model instance should be instantiated" );
        }
    }

    // singleton: always returns the one existing static instance to itself
    public static function getInstance() : Model {
        if ( myModel == null ){
            myModel = new Model();
        }
        return myModel;
    }

Then in the view code I have:

[Bindable] //do I actually need this?
private var myModel:Model = Model.getInstance();
var viewArray = new Array();
viewArray = myModel.myArray;

But it is coming back null. It isn’t null when I put a breakpoint in the Model class, but when I try to access it from the view class, it’s null. The model itself isn’t null, but that variable is.

What am I doing wrong?

Thanks.

  • 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-26T22:55:28+00:00Added an answer on May 26, 2026 at 10:55 pm

    First, if you are trying to make a singleton in AS3 you should first create a class, within the same class file as Model, that is used to ensure you can only create the class once.

    Add this class at the bottom of the Model class file (outside of the Model class):

    internal class SingletonEnforcer{} 
    

    Then create the Model constructor like this:

    public function Model(enforcer:SingletonEnforcer){ Init(); } // if init code is needed
    
    public static function get Instance():Model
    {
        if (!myModel){
            myModel = new Model(new SingletonEnforcer());
        }
        return myModel;
    }
    

    Now you don’t have to throw an exception for creating a second instance because it isn’t possible.

    I’m not sure about your first question of referencing your app’s main mxml, but if you were asking how to call the app that is running (like WindowedApplication in AIR) then you would call it like this:

    // my WindowedApplication file = MyApp.mxml
    MyApp(this.parentApplication)
    

    That will return the app’s instance.

    Once you’ve set up the Singleton like I have it above you should be able to access your array like:

    Model.Instance.myArray;
    

    I hope this helps!

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.