content.contentScopeFilter.addElement(c,dispatchEvent);
content.contentScopeFilter.dispatchEvent(new
Event("layoutNeeded"));
Why are you referencing content.contentScopeFilter instead of
this.contentScopeFilter ?
________________________________
From: Maria Jose Esteve <[email protected]>
Sent: Tuesday, May 7, 2024 12:25 AM
To: [email protected] <[email protected]>
Subject: Extend component mxml
Hello, let's see if anyone can give me “some clue” about my problem:
I have made many “base components” “.as” that I have then extended in several
mxml with success; Now I wanted to extend an mxml and I am having problems "add
components" because when "override addElement" is executed, in the extended
mxml component, the mxml elements that I use as a template are not yet created.
I'll give you an example because I don't know if I'm explaining myself well:
Success case, ".mxml" extended from ".as":
// ---- ModuleAssignTargetToScopeSectionContent.as
---------------------------------------
public class ModuleAssignTargetToScopeSectionContent extends SectionContent {
import com.xxx.xxx.models.ConfigModel;
…
public function ModuleAssignTargetToScopeSectionContent() {
super();
addEventListener("beadsAdded", beadsAddedHandler);
}
[Bindable]
[Inject(source="configModel", required="true")]
public var configModel:ConfigModel;
public var carFilter:IAssignScopeFilter;
public var carUnAssign:IUnAssignScope;
public var carAssign:IAssignScope;
public var header:HeaderModuleAssignTargetToScope = new
HeaderModuleAssignTargetToScope();
public var content:ContentModuleAssignTargetToScope = new
ContentModuleAssignTargetToScope(); //ex. VGroup
protected function beadsAddedHandler(event:Event):void
{
removeEventListener("beadsAdded", beadsAddedHandler);
if (getBeadByType(DataBindingBase) == null)
addBead(new ViewDataBinding());
strandChildren.addElement(content);
}
override public function addElement(c:IChild, dispatchEvent:Boolean =
true):void
{
if( c is IAssignScopeFilter )
{
carFilter = c as IAssignScopeFilter;
carFilter.moduleModel = moduleModel;
// content.contentScopeFilter --> Card
content.contentScopeFilter.addElement(c,dispatchEvent);
content.contentScopeFilter.dispatchEvent(new
Event("layoutNeeded"));
}
else if( c is IUnAssignScope ){
…
}else{
super.addElement(c, dispatchEvent);
}
}
override public function getElementIndex(c:IChild):int
{
if( c is IAssignScopeFilter )
{
return content.contentScopeFilter.getElementIndex(c);
}
else if( c is IUnAssignScope ){
…
}
return super.getElementIndex(c);
}
override public function removeElement(c:IChild, dispatchEvent:Boolean
= true):void
{
if( c is IAssignScopeFilter )
{
content.contentScopeFilter.removeElement(c,dispatchEvent);
}
else if( c is IUnAssignScope ){
…
}
super.removeElement(c, dispatchEvent);
}
…
}
// ---- AssignTargetToScopePerson.mxml ---------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<wp:ModuleAssignTargetToScopeSectionContent
xmlns="http://www.w3.org/1999/xhtml"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:j="library://ns.apache.org/royale/jewel"
xmlns:js="library://ns.apache.org/royale/basic"
xmlns:html="library://ns.apache.org/royale/html"
xmlns:wp="library://ns.xxx.com/xxx"
xmlns:viewsAssign="com.xxx.xxx.views.assignation.*">
<fx:Script>
<![CDATA[
…
]]>
</fx:Script>
<!-- implements "….supportClasses.IAssignScopeFilter" -->
<viewsAssign:PanelAssignScopePersonFilter localId="carFiltroPersonal"
percentWidth="100" percentHeight="100" />
<!-- implements "….supportClasses.IUnAssignScope" -->
<viewsAssign:PanelUnAssignScopePerson localId="carUnAssignPersonal"
percentWidth="100" percentHeight="100"
typeAssignment="{UtilConstants.CONST_TYPE_UNASSIGN}"/>
<!-- implements "….supportClasses.IAssignScope" -->
<viewsAssign:PanelAssignScopePerson localId="carAssignPersonal"
percentWidth="100" percentHeight="100"
typeAssignment="{UtilConstants.CONST_TYPE_ASSIGN}"/>
</wp:ModuleAssignTargetToScopeSectionContent>
Option that does not work, “.mxml” extended from another “.mxml”:
// ---- ModuleAssignTargetToScopeSectionContent.mxml
---------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<j:SectionContent
xmlns=http://www.w3.org/1999/xhtml
xmlns:fx=http://ns.adobe.com/mxml/2009
xmlns:j="library://ns.apache.org/royale/jewel"
xmlns:js="library://ns.apache.org/royale/basic"
xmlns:html="library://ns.apache.org/royale/html"
xmlns:wp="library://ns.xxx.com/xxx">
<fx:Script>
<![CDATA[
override public function addElement(c:IChild, dispatchEvent:Boolean =
true):void
{
if( c is IAssignScopeFilter )
{
carFilter = c as IAssignScopeFilter;
carFilter.moduleModel = moduleModel;
content.contentScopeFilter.addElement(c,dispatchEvent);
content.contentScopeFilter.dispatchEvent(new
Event("layoutNeeded"));
}
…
}
override public function getElementIndex(c:IChild):int
{
if( c is IAssignScopeFilter )
{
return content.contentScopeFilter.getElementIndex(c);
}
…
}
override public function removeElement(c:IChild, dispatchEvent:Boolean
= true):void
{
if( c is IAssignScopeFilter )
{
content.contentScopeFilter.removeElement(c,dispatchEvent);
}
…
}
…
]]>
</fx:Script>
<j:beads>
<js: ViewDataBinding/>
</j:beads>
<j:VGroup localId="content" percentHeight="100" percentWidth="100">
<j:Card localId="contentScopeFilter"
itemsVerticalAlign="itemsCenter" itemsHorizontalAlign="itemsRight">
</j:Card>
…
</j:VGroup>
</j:SectionContent>
// ---- AssignTargetToScopePerson2.mxml ---------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<wp:ModuleAssignTargetToScopeSectionContent
xmlns=http://www.w3.org/1999/xhtml
xmlns:fx=http://ns.adobe.com/mxml/2009
xmlns:j="library://ns.apache.org/royale/jewel"
xmlns:js="library://ns.apache.org/royale/basic"
xmlns:html="library://ns.apache.org/royale/html"
xmlns:wp="library://ns.xxx.com/xxx"
xmlns:viewsAssign="com.xxx.xxx.views.assignation.*">
<fx:Script>
<![CDATA[
…
]]>
</fx:Script>
<!-- implements "….supportClasses.IAssignScopeFilter" -->
<viewsAssign:PanelAssignScopePersonFilter localId="carFiltroPersonal"
percentWidth="100" percentHeight="100" />
<!-- implements "….supportClasses.IUnAssignScope" -->
<viewsAssign:PanelUnAssignScopePerson localId="carUnAssignPersonal"
percentWidth="100" percentHeight="100"
typeAssignment="{UtilConstants.CONST_TYPE_UNASSIGN}"/>
<!-- implements "….supportClasses.IAssignScope" -->
<viewsAssign:PanelAssignScopePerson localId="carAssignPersonal"
percentWidth="100" percentHeight="100"
typeAssignment="{UtilConstants.CONST_TYPE_ASSIGN}"/>
</wp:ModuleAssignTargetToScopeSectionContent>
The problem, as you have surely guessed, is that in
“AssignTargetToScopePerson2.mxml” the elements of the extended component
(viewsAssign:PanelAssignScopePersonFilter,…) are added before the elements of
the base component (content, contentScopeFilter,…)
How should I do it?
Any example I can investigate in the SDK?
If you see any “aberration” in the lines I have attached, please tell me 😝
Any help would be appreciated.
Thx.
Hiedra