2

i have a variable and i want to pu this variable in arraycollection or array using actionscript and flex

the following is code

var xyz:int=30;

var myArray:Array = [ {Month: "January", Views_Week1:xyz}, { Month: "June",        

    Views_Week2: 13 }, { Month:" December", Views_Week3: 14} ];

pageViews= new ArrayCollection(myArray);

or

pageViews= new ArrayCollection(myArray);
[
    { Month: January, Views_Week1: xyz},
    { Month:June, Views_Week2: 13},
    { Month: december, Views_Week3: 14}])

plz

0

2 Answers 2

1
pageViews= new ArrayCollection(myArray);

Looks fine. The second one however doesn't make sense where you are initializing the ArrayCollection and then trying to assign the objects again (which won't happen as there's the ; end-of-statement marker).

Does that not work for you?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply code is working fine ...actually dynamic variable i had created there was problem with that so it was not showing anyways thanks@mahesh p and @dirkgently
1

That does not work that way. When defining a variable, it is basically just present in that scope. You could declare it [Bindable] in the scope of a class, so the class would propagate changes with a PropertyChangeEvent of type PropertyChangeEvent.PROPERTY_CHANGE. This would allow you using BindingUtils, ChangeWatcher and MXML databinding with <{} /> declarative bindings.

You need to define a class, declare the class or a field [Bindable] and then create instances of the class and reference these through the ArrayCollection. Using vanilla object won't get you somewhere, since those can't dispatch Events.

    package
    {
      [Bindable]
      public class Person
      {
        public var name:String;

        public function Person(n:String)
        {
          name = n;
        }
      }
    }

    const source:Array = [new Person('Fred')]
        , collection:IList = new ArrayCollection(source);

Data binding relies on some key mechanisms like event dispatching, that is something to keep in mind. Also, in one way or the other, a reference to the data being changed need to in the different scopes, where the notification of the change is needed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.