2 Replies Latest reply on Jun 24, 2010 7:00 AM by BhaskerChari

    Sending Values between Classes

    logical_lunacy Level 1

      I have an actionscript class that looks like this:

       

       

      package com.ascentify.components.content.variables
      {
           import com.ascentify.components.content.events.ContentEvent;
           import com.ascentify.components.content.events.LoadContent;
          
           public class ZipVariables
           {
               private var _loadContent:LoadContent;


              private  var _positionArray:Array;
             
              public function  ZipVariables(section:String)
              {
                  _loadContent =  new LoadContent(section);
                   _loadContent.addEventListener(ContentEvent.POSTION_INTERVALS,  setPositionArray);

              }

              public function setPositionArray(e:ContentEvent):void
              {
                  positionArray = e.param.data as Array;
              }
             
              public function set positionArray(arr:Array):void
              {
                  _positionArray = arr;
              }

       

              public function get positionArray():Array
              {
                  return _positionArray;
              }

          }
      }

       

       

      When I attempt to get the value of the positionArray, the varaible is returned null.

       

           public var _zipVar:ZipVariables = new ZipVariables("story");

           trace(_zipVar.positionArray);

       

      Is there a way I can ensure that _zipVar.positionArray will not be returned until it is not longer null? Or a better way to send the value?

       

      Thanks!

        • 1. Re: Sending Values between Classes
          rootsounds Level 4

          If the property might be read before the loading has completed, then _positionArray should be initialized in the constructor to a new (empty) Array. I have no clue how your using this, but my guess is that you probably want to use data binding to notify of a change to the array.

          • 2. Re: Sending Values between Classes
            BhaskerChari Level 4

            Hi logical_lunacy,

             

            Try to dispatch an event in your ActionScript class when the setPositionArray(e:ContentEvent):void function in your AS class is called and listen for that event in your file where you are doing trace.

             

            I mean dispatch an event when your  _positionArray is poupulated in your AS file(Which is populated in set method positionArray() which is called after the below function in your AS file is executed...

             

            public function setPositionArray(e:ContentEvent):void
                    {
                        positionArray = e.param.data as Array;
                    }

            public function set positionArray(arr:Array):void
                    {
                        _positionArray = arr;

                          this.dispatchEvent(new Event("contentLoadComplete"));
                    }

            So after doing this listen for an event in your file where you want to access the array variable.

             

            this.addEventListener("contentLoadComplete", onContentLoadComplete);

            private function onContentLoadComplete(event:Event)

            {

                 trace(_zipVar.positionArray);

            }

             


            If this post answers your question or helps, please kindly mark it as such.


            Thanks,

            Bhasker Chari