Flex verification-submit mode source code parsing

Source: Internet
Author: User

1. Set component attributes

The following code is available in the component:

Public Function set XXX (value): void {

If (this. _ XXX! = Value ){

This. _ xxx = value;

Invalidateproerties ();

}

}

1. Call the invalidateproperties method of the uicomponent class:

public function invalidateProperties():void    {        if (!invalidatePropertiesFlag)        {            invalidatePropertiesFlag = true;            if (nestLevel && UIComponentGlobals.layoutManager)                UIComponentGlobals.layoutManager.invalidateProperties(this);        }    }

2. As shown in the code above, use the invalidateproperties method of layoutmanager

 public function invalidateProperties(obj:ILayoutManagerClient ):void    {        if (!invalidatePropertiesFlag && systemManager)        {            invalidatePropertiesFlag = true;            if (!listenersAttached)                attachListeners(systemManager);        }        // trace("LayoutManager adding " + Object(obj) + " to invalidatePropertiesQueue");        if (targetLevel <= obj.nestLevel)            invalidateClientPropertiesFlag = true;        invalidatePropertiesQueue.addObject(obj, obj.nestLevel);        // trace("LayoutManager added " + Object(obj) + " to invalidatePropertiesQueue");    }

3. The attachlisteners method adds a listener to systemmanager.

public function attachListeners(systemManager:ISystemManager):void    {        if (!waitedAFrame)        {            systemManager.addEventListener(Event.ENTER_FRAME, waitAFrame);        }        else        {            systemManager.addEventListener(Event.ENTER_FRAME, doPhasedInstantiationCallback);            if (!usePhasedInstantiation)            {                if (systemManager && (systemManager.stage || usingBridge(systemManager)))                {                    systemManager.addEventListener(Event.RENDER, doPhasedInstantiationCallback);                    if (systemManager.stage)                        systemManager.stage.invalidate();                }            }        }        listenersAttached = true;    }

4. Callback when the render event is triggered

 private function doPhasedInstantiationCallback(event:Event):void    {        // if our background processing is suspended, then we shouldn't do any         // validation        if (UIComponentGlobals.callLaterSuspendCount > 0)            return;                systemManager.removeEventListener(Event.ENTER_FRAME, doPhasedInstantiationCallback);        systemManager.removeEventListener(Event.RENDER, doPhasedInstantiationCallback);        if (!UIComponentGlobals.catchCallLaterExceptions)        {            doPhasedInstantiation();        }        else        {            try            {                doPhasedInstantiation();            }            catch(e:Error)            {                // Dispatch a callLaterError dynamic event for Design View.                 var callLaterErrorEvent:DynamicEvent = new DynamicEvent("callLaterError");                callLaterErrorEvent.error = e;                callLaterErrorEvent.source = this; callLaterErrorEvent.object = currentObject;                systemManager.dispatchEvent(callLaterErrorEvent);            }        }currentObject = null;    }

 

private function doPhasedInstantiation():void    {        // trace(">>DoPhasedInstantation");        // If phasing, do only one phase: validateProperties(),        // validateSize(), or validateDisplayList().        if (usePhasedInstantiation)        {            if (invalidatePropertiesFlag)            {                validateProperties();                // The Preloader listens for this event.                systemManager.document.dispatchEvent(                    new Event("validatePropertiesComplete"));            }            else if (invalidateSizeFlag)            {                validateSize();                // The Preloader listens for this event.                systemManager.document.dispatchEvent(                    new Event("validateSizeComplete"));            }            else if (invalidateDisplayListFlag)            {                validateDisplayList();                // The Preloader listens for this event.                systemManager.document.dispatchEvent(                    new Event("validateDisplayListComplete"));            }        }        // Otherwise, do one pass of all three phases.        else        {            if (invalidatePropertiesFlag)                validateProperties();            if (invalidateSizeFlag)                validateSize();            if (invalidateDisplayListFlag)                validateDisplayList();        }        // trace("invalidatePropertiesFlag " + invalidatePropertiesFlag);        // trace("invalidateSizeFlag " + invalidateSizeFlag);        // trace("invalidateDisplayListFlag " + invalidateDisplayListFlag);        if (invalidatePropertiesFlag ||            invalidateSizeFlag ||            invalidateDisplayListFlag)        {            attachListeners(systemManager);        }        else        {            usePhasedInstantiation = false;listenersAttached = false;var obj:ILayoutManagerClient = ILayoutManagerClient(updateCompleteQueue.removeLargest());            while (obj)            {                if (!obj.initialized && obj.processedDescriptors)                    obj.initialized = true;                if (obj.hasEventListener(FlexEvent.UPDATE_COMPLETE))                    obj.dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE));                obj.updateCompletePendingFlag = false;                obj = ILayoutManagerClient(updateCompleteQueue.removeLargest());            }            // trace("updateComplete");            dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE));        }        // trace("<<DoPhasedInstantation");    }

Note:

1. After the component calls the invalidateproperties () method, it calls the invalideproperties () of uicomponent ().

2. Call the invalidateproperties () method of layoutmanager.

3. Add a render event to systemmanager (this event can be triggered only when stage. invalidate () is required). This event is called when the display list is updated and displayed in the future.

4. After the render event is triggered, call the validateproperties () method of uicomponent.

5. Call the commitproperties () method. This method is usually rewritten when a custom component is used to delay verification-submission to this method. Rewrite some attributes to achieve partial refresh. For example:

override      protected      function commitProperties(): void      {      super.commitProperties();      if (sourceChanged){      if (! this.image){     image =  new Image();        this.addChild(image);     image.source =  this._source;        } else {     image.source =  this._source;      }     sourceChanged =  false ;      }      if (scaleChanged){      this.imageWidth =  this.imageWidth *   this.scale;      this.imageHeight =  this.imageHeight *+  this.scale;     scaleChanged =  false ;      }         }  

 

 

Invalidatesize ----> measure and invalidatedisplaylist --------> the updatedisplaylist process is the same as the preceding process.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.