You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@royale.apache.org by GitBox <gi...@apache.org> on 2020/11/17 14:56:03 UTC

[GitHub] [royale-asjs] Melliti opened a new issue #939: Access to parent functions

Melliti opened a new issue #939:
URL: https://github.com/apache/royale-asjs/issues/939


   During my work to migrate a flex project to Apache Royale, i faced a problem to access function from a parent file.
   
   <mx:Button text="Login" click="parentDocument.test_func()"/>
   
   I use Button from Jewel now but i hqve this error now:
   ***Access of possibly undefined property parentDocument.***
   
   on the doc I found
   ```Look for uses of ‘document’ and ‘parentDocument’ and change them to ‘component’ and ‘parentComponent’.```
   https://apache.github.io/royale-docs/migrate-an-existing-app/migrate-from-flex
   but parentComponent gives me the same error
   ***Access of possibly undefined property parentComponent.***
   
   Is it deprecated or renamed ? Do i miss something?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [royale-asjs] Melliti closed issue #939: Access to parent functions

Posted by GitBox <gi...@apache.org>.
Melliti closed issue #939:
URL: https://github.com/apache/royale-asjs/issues/939


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [royale-asjs] carlosrovira commented on issue #939: Access to parent functions

Posted by GitBox <gi...@apache.org>.
carlosrovira commented on issue #939:
URL: https://github.com/apache/royale-asjs/issues/939#issuecomment-732057905


   Glad you made it work :)
   
   Also, if you want even more pro solutions check Crux as a microframework to better organize event communication. Here's some links to help you start:
   
   https://apache.github.io/royale-docs/libraries/crux
   
   - ApacheCon2002: <a href="https://youtu.be/E-Fg5V5DxbY" target="_blank">Starting from a blank file (Youtube presentation)</a> - How to build a brand-new application using Royale's off-the-shelf resources including CRUX. <a href="https://apache.github.io/royale-docs/presentations/StartingFromABlankFile-ApacheCon2020.pdf" target="_blank">PDF of the slide presentation</a>


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [royale-asjs] Melliti commented on issue #939: Access to parent functions

Posted by GitBox <gi...@apache.org>.
Melliti commented on issue #939:
URL: https://github.com/apache/royale-asjs/issues/939#issuecomment-732040127


   Hi, 
   
   Yes it works perfectly ! this is the solution. Listen to the child file from the parent and trigger an event to call the parent function
   
   Thanks Carlos


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [royale-asjs] Melliti edited a comment on issue #939: Access to parent functions

Posted by GitBox <gi...@apache.org>.
Melliti edited a comment on issue #939:
URL: https://github.com/apache/royale-asjs/issues/939#issuecomment-729092897


   Thanks for your answer.
   
   I saw with my manager to share piece of code to be more specific with my issue.
   
   This is the initial code, **index.mxml** which includes **login.mxml** and after, the actual code in Apache Royale
   
   ***index.mxml***
   ```
   <?xml version="1.0" encoding="ISO-8859-1"?>
   <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="components.*" currentState="login" xmlns:ns3="components.message.*"
    backgroundColor="#FFFFFF" pageTitle="Portail v1.0" historyManagementEnabled="false" cachePolicy="off" xmlns:ns2="module.*" creationComplete="initMenu()">
   	<mx:states>
   		<mx:State name="login">
   			<mx:RemoveChild target="{myMenuBar}"/>
   			<mx:RemoveChild target="{text_where}"/>
   			<mx:RemoveChild target="{Container}"/>
   			<mx:RemoveChild target="{linkbutton1}"/>
   			<mx:AddChild position="lastChild">
   				<ns1:login horizontalCenter="0" top="50"></ns1:login>
   			</mx:AddChild>
   			<mx:RemoveChild target="{bt_bienvenue}"/>
   		</mx:State>
   	</mx:states>
   		<mx:Style source="styleCDP.css"/>
           <mx:Script source="conf.as"/>
           <mx:Script>
           	<![CDATA[
           		
   		
   		        [Bindable]
   	                private var xmlData:XMLList;
   			public var user:User;
   	            
                           public function verif_login(login:String,pass:String):void{
   					Authentification_service.endpoint = URL_SERVICE_WF;
   					Authentification_service.Login(login, pass,APPLICATION_ID);
   				}
           	]]>
           </mx:Script>
           <mx:RemoteObject id="Authentification_service" destination="amfphp" source="ene_ptam_navigation.WFN1" showBusyCursor="true" fault="faultResult(event)">
   		<mx:method name="Login"  result="LoginResult(event)" />
   	</mx:RemoteObject>
   	<mx:HTTPService id="menuService" url="menu.xml" result="resultHandler(event)" resultFormat="e4x"/>
   </mx:Application>
   
   ```
   
   ***login.mxml***
   ```
   <?xml version="1.0" encoding="ISO-8859-1"?>
   <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" height="190" width="350" styleName="glassPods" creationComplete="verif_sharedobject()">
   <mx:Script>
   	<![CDATA[
   		private function verif_sharedobject():void{
   			var sharedObject:SharedObject = SharedObject.getLocal("ftthmanager");
   			if (sharedObject.data.user != null){
   				login_login.text = sharedObject.data.user.name;
   				pass_login.text = sharedObject.data.user.pass;
   			}
   		}
   		private function save_sharedobject():void{
   			if(check_cookie.selected==true){
           		var sharedObject:SharedObject = SharedObject.getLocal("ftthmanager");
   				sharedObject.data.user = {name: login_login.text, pass: pass_login.text};
   				sharedObject.flush();
           	}
     		}
   	]]>
   </mx:Script>
   	<mx:Box styleName="glassPanel" width="100%">
   	<mx:Label text="Identification" styleName="glassLabels"  id="titre"/>
   </mx:Box>
   	<mx:Form id="loginForm" top="50" width="100%">
   		<mx:FormItem label="Login :" width="100%" id="label_login" horizontalAlign="right" fontWeight="bold" toolTip="Le login associ  votre compte">
   		    <mx:TextInput maxChars="40" width="160" id="login_login"/>
   		</mx:FormItem>
   		<mx:FormItem label="Mot de passe :" width="100%" id="label_pass" horizontalAlign="right" fontWeight="bold" toolTip="Le mot de passe associ  votre compte">
   		    <mx:TextInput maxChars="40" width="160" id="pass_login" displayAsPassword="true" enter="save_sharedobject();parentDocument.verif_login(login_login.text,pass_login.text);"/>
   		</mx:FormItem>
   		<mx:FormItem label="Se souvenir de moi" width="100%" id="label_pass0" fontWeight="bold" horizontalAlign="center" >
   		    <mx:CheckBox id="check_cookie" selected="true">
   		    </mx:CheckBox>
   		</mx:FormItem>
   	    </mx:Form>
   	<mx:Button label="Login" click="save_sharedobject();parentDocument.verif_login(login_login.text,pass_login.text);"  bottom="10" right="5" id="bt_login" height="30" buttonMode="true" useHandCursor="true" styleName="ButtonGrey"/>
   </mx:Canvas>
   
   ```
   This code isn't mine, it's from a previous developer long time ago. Sorry if it doesn't respect some design rules.
   As i said, my task is to turn this code into Apache Royale. I received the instruction to do it without modifying too much the code base.
   
   The updated version:
   ***index.mxml***
   ```
   <?xml version="1.0" encoding="UTF-8"?>
   <ex:Application xmlns:mx="http://ns.adobe.com/mxml/2009"
   	xmlns:fx="http://ns.adobe.com/mxml/2009"
   	xmlns:ry="library://ns.apache.org/royale/mx"
       xmlns:ex="library://ns.apache.org/royale/express"
       xmlns:jw="library://ns.apache.org/royale/jewel"
       xmlns:bs="library://ns.apache.org/royale/basic"
       xmlns:w3="library://ns.apache.org/royale/html"
       xmlns:ns1="components.*"
       xmlns:ns2="module.*"
       xmlns:ns3="components.message.*"
       pageTitle="Portail v1.0">
   
       <fx:Script>
   		<![CDATA[
                         public function verif_login(login:String,pass:String):void{
                                 Authentification_service.endpoint = URL_SERVICE_WF;
                                 Authentification_service.Login(login, pass,APPLICATION_ID);
                        }
   		]]>
   	</fx:Script>
           <fx:Declarations>
                <bs:RemoteObject id="Authentification_service" destination="amfphp" endPoint="" fault="faultResult(event)" result="LoginResult(event)"/>
       </fx:Declarations>
       <ex:initialView>
           <jw:View id="maVue">
               <jw:Card id="loginForm" includeIn="login">
                   <ns1:login />
               </jw:Card>
           </jw:View>
       </ex:initialView>
   </ex:Application>
   ```
   
   ***login.mxml***
   ```<?xml version="1.0" encoding="ISO-8859-1"?>
   <js:Container
   	xmlns:fx="http://ns.adobe.com/mxml/2009"
   	xmlns:mx="library://ns.apache.org/royale/mx"
       xmlns:js="library://ns.apache.org/royale/express"
       xmlns:jw="library://ns.apache.org/royale/jewel"
   	height="190" width="350" className="glassPods" initComplete="verif_sharedobject()">
   	<!-- height="190" width="350" styleName="glassPods" creationComplete="verif_sharedobject()"> -->
   	<fx:Script>
   		<![CDATA[
   			import mx.net.SharedObject;
   
   			private function verif_sharedobject():void{
   				console.log("Foo")
   				trace("Bar")
   				var sharedObject:SharedObject = SharedObject.getLocal("ftthmanager");
   				if (sharedObject.data.user != null){
   					login_login.text = sharedObject.data.user.name;
   					pass_login.text = sharedObject.data.user.pass;
   				}
   			}
   			private function save_sharedobject():void{
   				if(check_cookie.selected==true){
   					var sharedObject:SharedObject = SharedObject.getLocal("ftthmanager");
   					sharedObject.data.user = {name: login_login.text, pass: pass_login.text};
   					sharedObject.flush();
   				}
   			}
   		]]>
   	</fx:Script>
   	<jw:HGroup className="glassPanel" width="100%">
   		<jw:Label text="Identification" className="glassLabels"  id="titre"/>
   	</jw:HGroup>
   	<jw:Form id="loginForm" y="50" width="100%">
   		<jw:FormItem label="Login :" width="100%" id="label_login">
   		    <jw:TextInput width="160" id="login_login">
   				<jw:beads>
   					<jw:MaxNumberCharacters maxlength="40"/>
   				</jw:beads>
   			</jw:TextInput>
   		</jw:FormItem>
   		<jw:FormItem label="Mot de passe :" width="100%" id="label_pass" >
   		    <jw:TextInput width="160" id="pass_login" enter="save_sharedobject() parentDocument.verif_login(login_login.text,pass_login.text);">
   				<jw:beads>
   					<jw:PasswordInput />
   					<jw:MaxNumberCharacters maxlength="40"/>
   				</jw:beads>
   			</jw:TextInput>
   		</jw:FormItem>
   		<jw:FormItem label="Se souvenir de moi" width="100%" id="label_pass0">
   		    <js:CheckBox id="check_cookie" selected="true">
   		    </js:CheckBox>
   		</jw:FormItem>
   			<jw:Button text="Login" click="parent.verif_sharedobject()" id="bt_login" height="30" className="ButtonGrey"/>
   		<jw:Button text="triche" id="bt_login0" height="30" visible="false"/>
   	</jw:Form>
   </js:Container>
   ```
   
   
   ### As a reminder, I must find a way to call verif_login() which is in **index.mxml** from **login.mxml** when my button is clicked.
   
   As you can see we use Beads for some cases but for my problem I don't see how to implement your suggestion to this code. Jewel.Button doesn't have ParentDocumentBead in its beads list
   https://apache.github.io/royale-docs/component-sets/jewel/button
   
   I also found it's possible to add beads through actionScript:
   https://apache.github.io/royale-docs/features/strands-and-beads
   
   I made many link in my head reading the documentation helped by your previous post and I archieve few lines without error but I still have no idea about how to access parent method. Here some lines I tried after reading your post:
   
   ```
   		var buttonBead:IBead = bt_login.getBeadByType(IChild);
   		bt_login.addBead(buttonBead);
   		bt_login.verif_login(login_login.text,pass_login.text); // This line fails, it was just a test
   		var parentMethod:ParentDocumentBead = new ParentDocumentBead();
   ```
   
   If you have more explanation or idea about how to fix this
   
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [royale-asjs] Melliti edited a comment on issue #939: Access to parent functions

Posted by GitBox <gi...@apache.org>.
Melliti edited a comment on issue #939:
URL: https://github.com/apache/royale-asjs/issues/939#issuecomment-729092897


   Thanks for your answer.
   
   I saw with my manager to share piece of code to be more specific with my issue.
   
   This is the initial code, **index.mxml** which includes **login.mxml** and after, the actual code in Apache Royale
   
   ***index.mxml***
   ```
   <?xml version="1.0" encoding="ISO-8859-1"?>
   <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="components.*" currentState="login" xmlns:ns3="components.message.*"
    backgroundColor="#FFFFFF" pageTitle="Portail v1.0" historyManagementEnabled="false" cachePolicy="off" xmlns:ns2="module.*" creationComplete="initMenu()">
   	<mx:states>
   		<mx:State name="login">
   			<mx:RemoveChild target="{myMenuBar}"/>
   			<mx:RemoveChild target="{text_where}"/>
   			<mx:RemoveChild target="{Container}"/>
   			<mx:RemoveChild target="{linkbutton1}"/>
   			<mx:AddChild position="lastChild">
   				<ns1:login horizontalCenter="0" top="50"></ns1:login>
   			</mx:AddChild>
   			<mx:RemoveChild target="{bt_bienvenue}"/>
   		</mx:State>
   	</mx:states>
   		<mx:Style source="styleCDP.css"/>
           <mx:Script source="conf.as"/>
           <mx:Script>
           	<![CDATA[
           		
   		
   		        [Bindable]
   	                private var xmlData:XMLList;
   			public var user:User;
   	            
                           public function verif_login(login:String,pass:String):void{
   					Authentification_service.endpoint = URL_SERVICE_WF;
   					Authentification_service.Login(login, pass,APPLICATION_ID);
   				}
           	]]>
           </mx:Script>
           <mx:RemoteObject id="Authentification_service" destination="amfphp" source="ene_ptam_navigation.WFN1" showBusyCursor="true" fault="faultResult(event)">
   		<mx:method name="Login"  result="LoginResult(event)" />
   	</mx:RemoteObject>
   	<mx:HTTPService id="menuService" url="menu.xml" result="resultHandler(event)" resultFormat="e4x"/>
   </mx:Application>
   
   ```
   
   ***login.mxml***
   ```
   <?xml version="1.0" encoding="ISO-8859-1"?>
   <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" height="190" width="350" styleName="glassPods" creationComplete="verif_sharedobject()">
   <mx:Script>
   	<![CDATA[
   		private function verif_sharedobject():void{
   			var sharedObject:SharedObject = SharedObject.getLocal("ftthmanager");
   			if (sharedObject.data.user != null){
   				login_login.text = sharedObject.data.user.name;
   				pass_login.text = sharedObject.data.user.pass;
   			}
   		}
   		private function save_sharedobject():void{
   			if(check_cookie.selected==true){
           		var sharedObject:SharedObject = SharedObject.getLocal("ftthmanager");
   				sharedObject.data.user = {name: login_login.text, pass: pass_login.text};
   				sharedObject.flush();
           	}
     		}
   	]]>
   </mx:Script>
   	<mx:Box styleName="glassPanel" width="100%">
   	<mx:Label text="Identification" styleName="glassLabels"  id="titre"/>
   </mx:Box>
   	<mx:Form id="loginForm" top="50" width="100%">
   		<mx:FormItem label="Login :" width="100%" id="label_login" horizontalAlign="right" fontWeight="bold" toolTip="Le login associ  votre compte">
   		    <mx:TextInput maxChars="40" width="160" id="login_login"/>
   		</mx:FormItem>
   		<mx:FormItem label="Mot de passe :" width="100%" id="label_pass" horizontalAlign="right" fontWeight="bold" toolTip="Le mot de passe associ  votre compte">
   		    <mx:TextInput maxChars="40" width="160" id="pass_login" displayAsPassword="true" enter="save_sharedobject();parentDocument.verif_login(login_login.text,pass_login.text);"/>
   		</mx:FormItem>
   		<mx:FormItem label="Se souvenir de moi" width="100%" id="label_pass0" fontWeight="bold" horizontalAlign="center" >
   		    <mx:CheckBox id="check_cookie" selected="true">
   		    </mx:CheckBox>
   		</mx:FormItem>
   	    </mx:Form>
   	<mx:Button label="Login" click="save_sharedobject();parentDocument.verif_login(login_login.text,pass_login.text);"  bottom="10" right="5" id="bt_login" height="30" buttonMode="true" useHandCursor="true" styleName="ButtonGrey"/>
   </mx:Canvas>
   
   ```
   This code isn't mine, it's from a previous developer long time ago. Sorry if it doesn't respect some design rules.
   As i said, my task is to turn this code into Apache Royale. I received the instruction to do it without modifying too much the code base.
   
   The updated version:
   ***index.mxml***
   ```
   <?xml version="1.0" encoding="UTF-8"?>
   <ex:Application xmlns:mx="http://ns.adobe.com/mxml/2009"
   	xmlns:fx="http://ns.adobe.com/mxml/2009"
   	xmlns:ry="library://ns.apache.org/royale/mx"
       xmlns:ex="library://ns.apache.org/royale/express"
       xmlns:jw="library://ns.apache.org/royale/jewel"
       xmlns:bs="library://ns.apache.org/royale/basic"
       xmlns:w3="library://ns.apache.org/royale/html"
       xmlns:ns1="components.*"
       xmlns:ns2="module.*"
       xmlns:ns3="components.message.*"
       pageTitle="Portail v1.0">
   
       <fx:Script>
   		<![CDATA[
                         public function verif_login(login:String,pass:String):void{
                                 Authentification_service.endpoint = URL_SERVICE_WF;
                                 Authentification_service.Login(login, pass,APPLICATION_ID);
                        }
   		]]>
   	</fx:Script>
           <fx:Declarations>
                <bs:RemoteObject id="Authentification_service" destination="amfphp" endPoint="1.2.3.4" fault="faultResult(event)" result="LoginResult(event)"/>
       </fx:Declarations>
       <ex:initialView>
           <jw:View id="maVue">
               <jw:Card id="loginForm" includeIn="login">
                   <ns1:login />
               </jw:Card>
           </jw:View>
       </ex:initialView>
   </ex:Application>
   ```
   
   ***login.mxml***
   ```<?xml version="1.0" encoding="ISO-8859-1"?>
   <js:Container
   	xmlns:fx="http://ns.adobe.com/mxml/2009"
   	xmlns:mx="library://ns.apache.org/royale/mx"
       xmlns:js="library://ns.apache.org/royale/express"
       xmlns:jw="library://ns.apache.org/royale/jewel"
   	height="190" width="350" className="glassPods" initComplete="verif_sharedobject()">
   	<!-- height="190" width="350" styleName="glassPods" creationComplete="verif_sharedobject()"> -->
   	<fx:Script>
   		<![CDATA[
   			import mx.net.SharedObject;
   
   			private function verif_sharedobject():void{
   				console.log("Foo")
   				trace("Bar")
   				var sharedObject:SharedObject = SharedObject.getLocal("ftthmanager");
   				if (sharedObject.data.user != null){
   					login_login.text = sharedObject.data.user.name;
   					pass_login.text = sharedObject.data.user.pass;
   				}
   			}
   			private function save_sharedobject():void{
   				if(check_cookie.selected==true){
   					var sharedObject:SharedObject = SharedObject.getLocal("ftthmanager");
   					sharedObject.data.user = {name: login_login.text, pass: pass_login.text};
   					sharedObject.flush();
   				}
   			}
   		]]>
   	</fx:Script>
   	<jw:HGroup className="glassPanel" width="100%">
   		<jw:Label text="Identification" className="glassLabels"  id="titre"/>
   	</jw:HGroup>
   	<jw:Form id="loginForm" y="50" width="100%">
   		<jw:FormItem label="Login :" width="100%" id="label_login">
   		    <jw:TextInput width="160" id="login_login">
   				<jw:beads>
   					<jw:MaxNumberCharacters maxlength="40"/>
   				</jw:beads>
   			</jw:TextInput>
   		</jw:FormItem>
   		<jw:FormItem label="Mot de passe :" width="100%" id="label_pass" >
   		    <jw:TextInput width="160" id="pass_login" enter="save_sharedobject() parentDocument.verif_login(login_login.text,pass_login.text);">
   				<jw:beads>
   					<jw:PasswordInput />
   					<jw:MaxNumberCharacters maxlength="40"/>
   				</jw:beads>
   			</jw:TextInput>
   		</jw:FormItem>
   		<jw:FormItem label="Se souvenir de moi" width="100%" id="label_pass0">
   		    <js:CheckBox id="check_cookie" selected="true">
   		    </js:CheckBox>
   		</jw:FormItem>
   			<jw:Button text="Login" click="parent.verif_sharedobject()" id="bt_login" height="30" className="ButtonGrey"/>
   		<jw:Button text="triche" id="bt_login0" height="30" visible="false"/>
   	</jw:Form>
   </js:Container>
   ```
   
   
   ### As a reminder, I must find a way to call verif_login() which is in **index.mxml** from **login.mxml** when my button is clicked.
   
   As you can see we use Beads for some cases but for my problem I don't see how to implement your suggestion to this code. Jewel.Button doesn't have ParentDocumentBead in its beads list
   https://apache.github.io/royale-docs/component-sets/jewel/button
   
   I also found it's possible to add beads through actionScript:
   https://apache.github.io/royale-docs/features/strands-and-beads
   
   I made many link in my head reading the documentation helped by your previous post and I archieve few lines without error but I still have no idea about how to access parent method. Here some lines I tried after reading your post:
   
   ```
   		var buttonBead:IBead = bt_login.getBeadByType(IChild);
   		bt_login.addBead(buttonBead);
   		bt_login.verif_login(login_login.text,pass_login.text); // This line fails, it was just a test
   		var parentMethod:ParentDocumentBead = new ParentDocumentBead();
   ```
   
   If you have more explanation or idea about how to fix this
   
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [royale-asjs] Melliti commented on issue #939: Access to parent functions

Posted by GitBox <gi...@apache.org>.
Melliti commented on issue #939:
URL: https://github.com/apache/royale-asjs/issues/939#issuecomment-729092897


   Thanks for your answer.
   
   I saw with my manager to share piece of code to be more specific with my issue.
   
   This is the initial code, **index.mxml** which includes **login.mxml** and after, the actual code in Apache Royale
   
   ***index.mxml***
   ```
   <?xml version="1.0" encoding="ISO-8859-1"?>
   <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="components.*" currentState="login" xmlns:ns3="components.message.*"
    backgroundColor="#FFFFFF" pageTitle="Portail v1.0" historyManagementEnabled="false" cachePolicy="off" xmlns:ns2="module.*" creationComplete="initMenu()">
   	<mx:states>
   		<mx:State name="login">
   			<mx:RemoveChild target="{myMenuBar}"/>
   			<mx:RemoveChild target="{text_where}"/>
   			<mx:RemoveChild target="{Container}"/>
   			<mx:RemoveChild target="{linkbutton1}"/>
   			<mx:AddChild position="lastChild">
   				<ns1:login horizontalCenter="0" top="50"></ns1:login>
   			</mx:AddChild>
   			<mx:RemoveChild target="{bt_bienvenue}"/>
   		</mx:State>
   	</mx:states>
   		<mx:Style source="styleCDP.css"/>
           <mx:Script source="conf.as"/>
           <mx:Script>
           	<![CDATA[
           		
   		
   		        [Bindable]
   	                private var xmlData:XMLList;
   			public var user:User;
   	            
                           public function verif_login(login:String,pass:String):void{
   					Authentification_service.endpoint = URL_SERVICE_WF;
   					Authentification_service.Login(login, pass,APPLICATION_ID);
   				}
           	]]>
           </mx:Script>
           <mx:RemoteObject id="Authentification_service" destination="amfphp" source="ene_ptam_navigation.WFN1" showBusyCursor="true" fault="faultResult(event)">
   		<mx:method name="Login"  result="LoginResult(event)" />
   	</mx:RemoteObject>
   	<mx:HTTPService id="menuService" url="menu.xml" result="resultHandler(event)" resultFormat="e4x"/>
   </mx:Application>
   
   ```
   
   ***login.mxml***
   ```
   <?xml version="1.0" encoding="ISO-8859-1"?>
   <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" height="190" width="350" styleName="glassPods" creationComplete="verif_sharedobject()">
   <mx:Script>
   	<![CDATA[
   		private function verif_sharedobject():void{
   			var sharedObject:SharedObject = SharedObject.getLocal("ftthmanager");
   			if (sharedObject.data.user != null){
   				login_login.text = sharedObject.data.user.name;
   				pass_login.text = sharedObject.data.user.pass;
   			}
   		}
   		private function save_sharedobject():void{
   			if(check_cookie.selected==true){
           		var sharedObject:SharedObject = SharedObject.getLocal("ftthmanager");
   				sharedObject.data.user = {name: login_login.text, pass: pass_login.text};
   				sharedObject.flush();
           	}
     		}
   	]]>
   </mx:Script>
   	<mx:Box styleName="glassPanel" width="100%">
   	<mx:Label text="Identification" styleName="glassLabels"  id="titre"/>
   </mx:Box>
   	<mx:Form id="loginForm" top="50" width="100%">
   		<mx:FormItem label="Login :" width="100%" id="label_login" horizontalAlign="right" fontWeight="bold" toolTip="Le login associ  votre compte">
   		    <mx:TextInput maxChars="40" width="160" id="login_login"/>
   		</mx:FormItem>
   		<mx:FormItem label="Mot de passe :" width="100%" id="label_pass" horizontalAlign="right" fontWeight="bold" toolTip="Le mot de passe associ  votre compte">
   		    <mx:TextInput maxChars="40" width="160" id="pass_login" displayAsPassword="true" enter="save_sharedobject();parentDocument.verif_login(login_login.text,pass_login.text);"/>
   		</mx:FormItem>
   		<mx:FormItem label="Se souvenir de moi" width="100%" id="label_pass0" fontWeight="bold" horizontalAlign="center" >
   		    <mx:CheckBox id="check_cookie" selected="true">
   		    </mx:CheckBox>
   		</mx:FormItem>
   	    </mx:Form>
   	<mx:Button label="Login" click="save_sharedobject();parentDocument.verif_login(login_login.text,pass_login.text);"  bottom="10" right="5" id="bt_login" height="30" buttonMode="true" useHandCursor="true" styleName="ButtonGrey"/>
   </mx:Canvas>
   
   ```
   This code isn't mine, it's from a previous developer long time ago. Sorry if it doesn't respect some design rules.
   As i said, my task is to turn this code into Apache Royale. I received the instruction to do it without modifying too much the code base.
   
   The updated version:
   ***index.mxml***
   ```
   <?xml version="1.0" encoding="UTF-8"?>
   <ex:Application xmlns:mx="http://ns.adobe.com/mxml/2009"
   	xmlns:fx="http://ns.adobe.com/mxml/2009"
   	xmlns:ry="library://ns.apache.org/royale/mx"
       xmlns:ex="library://ns.apache.org/royale/express"
       xmlns:jw="library://ns.apache.org/royale/jewel"
       xmlns:bs="library://ns.apache.org/royale/basic"
       xmlns:w3="library://ns.apache.org/royale/html"
       xmlns:ns1="components.*"
       xmlns:ns2="module.*"
       xmlns:ns3="components.message.*"
       pageTitle="Portail v1.0">
   
       <fx:Script>
   		<![CDATA[
                         public function verif_login(login:String,pass:String):void{
                                 Authentification_service.endpoint = URL_SERVICE_WF;
                                 Authentification_service.Login(login, pass,APPLICATION_ID);
                        }
   		]]>
   	</fx:Script>
           <fx:Declarations>
                <bs:RemoteObject id="Authentification_service" destination="amfphp" endPoint="http://10.129.57.12/workflow/amfphp/gateway.php" fault="faultResult(event)" result="LoginResult(event)"/>
       </fx:Declarations>
       <ex:initialView>
           <jw:View id="maVue">
               <jw:Card id="loginForm" includeIn="login">
                   <ns1:login />
               </jw:Card>
           </jw:View>
       </ex:initialView>
   </ex:Application>
   ```
   
   ***login.mxml***
   ```<?xml version="1.0" encoding="ISO-8859-1"?>
   <js:Container
   	xmlns:fx="http://ns.adobe.com/mxml/2009"
   	xmlns:mx="library://ns.apache.org/royale/mx"
       xmlns:js="library://ns.apache.org/royale/express"
       xmlns:jw="library://ns.apache.org/royale/jewel"
   	height="190" width="350" className="glassPods" initComplete="verif_sharedobject()">
   	<!-- height="190" width="350" styleName="glassPods" creationComplete="verif_sharedobject()"> -->
   	<fx:Script>
   		<![CDATA[
   			import mx.net.SharedObject;
   
   			private function verif_sharedobject():void{
   				console.log("Foo")
   				trace("Bar")
   				var sharedObject:SharedObject = SharedObject.getLocal("ftthmanager");
   				if (sharedObject.data.user != null){
   					login_login.text = sharedObject.data.user.name;
   					pass_login.text = sharedObject.data.user.pass;
   				}
   			}
   			private function save_sharedobject():void{
   				if(check_cookie.selected==true){
   					var sharedObject:SharedObject = SharedObject.getLocal("ftthmanager");
   					sharedObject.data.user = {name: login_login.text, pass: pass_login.text};
   					sharedObject.flush();
   				}
   			}
   		]]>
   	</fx:Script>
   	<jw:HGroup className="glassPanel" width="100%">
   		<jw:Label text="Identification" className="glassLabels"  id="titre"/>
   	</jw:HGroup>
   	<jw:Form id="loginForm" y="50" width="100%">
   		<jw:FormItem label="Login :" width="100%" id="label_login">
   		    <jw:TextInput width="160" id="login_login">
   				<jw:beads>
   					<jw:MaxNumberCharacters maxlength="40"/>
   				</jw:beads>
   			</jw:TextInput>
   		</jw:FormItem>
   		<jw:FormItem label="Mot de passe :" width="100%" id="label_pass" >
   		    <jw:TextInput width="160" id="pass_login" enter="save_sharedobject() parentDocument.verif_login(login_login.text,pass_login.text);">
   				<jw:beads>
   					<jw:PasswordInput />
   					<jw:MaxNumberCharacters maxlength="40"/>
   				</jw:beads>
   			</jw:TextInput>
   		</jw:FormItem>
   		<jw:FormItem label="Se souvenir de moi" width="100%" id="label_pass0">
   		    <js:CheckBox id="check_cookie" selected="true">
   		    </js:CheckBox>
   		</jw:FormItem>
   			<jw:Button text="Login" click="parent.verif_sharedobject()" id="bt_login" height="30" className="ButtonGrey"/>
   		<jw:Button text="triche" id="bt_login0" height="30" visible="false"/>
   	</jw:Form>
   </js:Container>
   ```
   
   
   ### As a reminder, I must find a way to call verif_login() which is in **index.mxml** from **login.mxml** when my button is clicked.
   
   As you can see we use Beads for some cases but for my problem I don't see how to implement your suggestion to this code. Jewel.Button doesn't have ParentDocumentBead in its beads list
   https://apache.github.io/royale-docs/component-sets/jewel/button
   
   I also found it's possible to add beads through actionScript:
   https://apache.github.io/royale-docs/features/strands-and-beads
   
   I made many link in my head reading the documentation helped by your previous post and I archieve few lines without error but I still have no idea about how to access parent method. Here some lines I tried after reading your post:
   
   ```
   		var buttonBead:IBead = bt_login.getBeadByType(IChild);
   		bt_login.addBead(buttonBead);
   		bt_login.verif_login(login_login.text,pass_login.text); // This line fails, it was just a test
   		var parentMethod:ParentDocumentBead = new ParentDocumentBead();
   ```
   
   If you have an idea
   
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [royale-asjs] carlosrovira commented on issue #939: Access to parent functions

Posted by GitBox <gi...@apache.org>.
carlosrovira commented on issue #939:
URL: https://github.com/apache/royale-asjs/issues/939#issuecomment-730670156


   Hi, 
   
   before going further, for next questions please try to shrink to the minimun expression since this kind of long question are hard to follow.
   
   About how to solve your problem. I think best way is to use events:
   
   1 - In your inner component (in your case your login form) you can have a button that create an event:
   
   ```mxml
   <j:Button click="sendSomeEvent();" text="send event"/>
   ````
   and
   ```as3
   private function sendSomeEvent():void {
   	var e:Event = new Event('MY_EVENT');
   	dispatchEvent(e);
   }
   ```
   
   then in your main component you must listen for that event.
   
   Let's say that your login form has a `localID="myloginForm"`
   
   ```as3
   myloginForm.addEventListener('MY_EVENT', myEventHandler);
   ```
   
   then  you have the event handler:
   
   ```as3
   public function myEventHandler(e:Event):void
   {
       trace("do something");
   }
   ```
   
   another  way to solve with events is to use `bubbling events` adding `true` as the second param in the event `var e:Event = new Event('MY_EVENT', true);`, then this event will bubble over the DOM to reach the main component and you can just listen `addEventListener('MY_EVENT', myEventHandler);` (without using `myloginForm`)
   
   HTH
   
   Carlos


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [royale-asjs] carlosrovira commented on issue #939: Access to parent functions

Posted by GitBox <gi...@apache.org>.
carlosrovira commented on issue #939:
URL: https://github.com/apache/royale-asjs/issues/939#issuecomment-729015039


   Hi
   
   I never used that approach since it couples files and is bad design. I recommend you to comunicate via composition and events.
   
   Anyway, I looked for your problems and I think you need the following bead:
   
   ```/**
        *  The ParentDocumentBead class looks up the parent
        *  chain to find a parent that was written in MXML.
        *  Because it is usually rare for an application
        *  to need to know this information, an optional bead
        *  is used to compute it, instead of baking in the
        *  overhead of a recursive infrastucture to store
        *  this information.  It is intended to be used
        *  as a bead in the top-level tag of an MXML document.
        *  
        *  @royaleignoreimport org.apache.royale.core.IChild
        * 
        *  @langversion 3.0
        *  @playerversion Flash 10.2
        *  @playerversion AIR 2.6
        *  @productversion Royale 0.0
        */
   	public class ParentDocumentBead extends DispatcherBead
   ```
   
   Also we have `parent` in each component but I think you want the previous bead to refer to the parent MXML file.
   
   HTH


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [royale-asjs] Melliti edited a comment on issue #939: Access to parent functions

Posted by GitBox <gi...@apache.org>.
Melliti edited a comment on issue #939:
URL: https://github.com/apache/royale-asjs/issues/939#issuecomment-729092897


   Thanks for your answer.
   
   I saw with my manager to share piece of code to be more specific with my issue.
   
   This is the initial code, **index.mxml** which includes **login.mxml** and after, the actual code in Apache Royale
   
   ***index.mxml***
   ```
   <?xml version="1.0" encoding="ISO-8859-1"?>
   <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="components.*" currentState="login" xmlns:ns3="components.message.*"
    backgroundColor="#FFFFFF" pageTitle="Portail v1.0" historyManagementEnabled="false" cachePolicy="off" xmlns:ns2="module.*" creationComplete="initMenu()">
   	<mx:states>
   		<mx:State name="login">
   			<mx:RemoveChild target="{myMenuBar}"/>
   			<mx:RemoveChild target="{text_where}"/>
   			<mx:RemoveChild target="{Container}"/>
   			<mx:RemoveChild target="{linkbutton1}"/>
   			<mx:AddChild position="lastChild">
   				<ns1:login horizontalCenter="0" top="50"></ns1:login>
   			</mx:AddChild>
   			<mx:RemoveChild target="{bt_bienvenue}"/>
   		</mx:State>
   	</mx:states>
   		<mx:Style source="styleCDP.css"/>
           <mx:Script source="conf.as"/>
           <mx:Script>
           	<![CDATA[
           		
   		
   		        [Bindable]
   	                private var xmlData:XMLList;
   			public var user:User;
   	            
                           public function verif_login(login:String,pass:String):void{
   					Authentification_service.endpoint = URL_SERVICE_WF;
   					Authentification_service.Login(login, pass,APPLICATION_ID);
   				}
           	]]>
           </mx:Script>
           <mx:RemoteObject id="Authentification_service" destination="amfphp" source="ene_ptam_navigation.WFN1" showBusyCursor="true" fault="faultResult(event)">
   		<mx:method name="Login"  result="LoginResult(event)" />
   	</mx:RemoteObject>
   	<mx:HTTPService id="menuService" url="menu.xml" result="resultHandler(event)" resultFormat="e4x"/>
   </mx:Application>
   
   ```
   
   ***login.mxml***
   ```
   <?xml version="1.0" encoding="ISO-8859-1"?>
   <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" height="190" width="350" styleName="glassPods" creationComplete="verif_sharedobject()">
   <mx:Script>
   	<![CDATA[
   		private function verif_sharedobject():void{
   			var sharedObject:SharedObject = SharedObject.getLocal("ftthmanager");
   			if (sharedObject.data.user != null){
   				login_login.text = sharedObject.data.user.name;
   				pass_login.text = sharedObject.data.user.pass;
   			}
   		}
   		private function save_sharedobject():void{
   			if(check_cookie.selected==true){
           		var sharedObject:SharedObject = SharedObject.getLocal("ftthmanager");
   				sharedObject.data.user = {name: login_login.text, pass: pass_login.text};
   				sharedObject.flush();
           	}
     		}
   	]]>
   </mx:Script>
   	<mx:Box styleName="glassPanel" width="100%">
   	<mx:Label text="Identification" styleName="glassLabels"  id="titre"/>
   </mx:Box>
   	<mx:Form id="loginForm" top="50" width="100%">
   		<mx:FormItem label="Login :" width="100%" id="label_login" horizontalAlign="right" fontWeight="bold" toolTip="Le login associ  votre compte">
   		    <mx:TextInput maxChars="40" width="160" id="login_login"/>
   		</mx:FormItem>
   		<mx:FormItem label="Mot de passe :" width="100%" id="label_pass" horizontalAlign="right" fontWeight="bold" toolTip="Le mot de passe associ  votre compte">
   		    <mx:TextInput maxChars="40" width="160" id="pass_login" displayAsPassword="true" enter="save_sharedobject();parentDocument.verif_login(login_login.text,pass_login.text);"/>
   		</mx:FormItem>
   		<mx:FormItem label="Se souvenir de moi" width="100%" id="label_pass0" fontWeight="bold" horizontalAlign="center" >
   		    <mx:CheckBox id="check_cookie" selected="true">
   		    </mx:CheckBox>
   		</mx:FormItem>
   	    </mx:Form>
   	<mx:Button label="Login" click="save_sharedobject();parentDocument.verif_login(login_login.text,pass_login.text);"  bottom="10" right="5" id="bt_login" height="30" buttonMode="true" useHandCursor="true" styleName="ButtonGrey"/>
   </mx:Canvas>
   
   ```
   This code isn't mine, it's from a previous developer long time ago. Sorry if it doesn't respect some design rules.
   As i said, my task is to turn this code into Apache Royale. I received the instruction to do it without modifying too much the code base.
   
   The updated version:
   ***index.mxml***
   ```
   <?xml version="1.0" encoding="UTF-8"?>
   <ex:Application xmlns:mx="http://ns.adobe.com/mxml/2009"
   	xmlns:fx="http://ns.adobe.com/mxml/2009"
   	xmlns:ry="library://ns.apache.org/royale/mx"
       xmlns:ex="library://ns.apache.org/royale/express"
       xmlns:jw="library://ns.apache.org/royale/jewel"
       xmlns:bs="library://ns.apache.org/royale/basic"
       xmlns:w3="library://ns.apache.org/royale/html"
       xmlns:ns1="components.*"
       xmlns:ns2="module.*"
       xmlns:ns3="components.message.*"
       pageTitle="Portail v1.0">
   
       <fx:Script>
   		<![CDATA[
                         public function verif_login(login:String,pass:String):void{
                                 Authentification_service.endpoint = URL_SERVICE_WF;
                                 Authentification_service.Login(login, pass,APPLICATION_ID);
                        }
   		]]>
   	</fx:Script>
           <fx:Declarations>
                <bs:RemoteObject id="Authentification_service" destination="amfphp" endPoint="http://10.129.57.12/workflow/amfphp/gateway.php" fault="faultResult(event)" result="LoginResult(event)"/>
       </fx:Declarations>
       <ex:initialView>
           <jw:View id="maVue">
               <jw:Card id="loginForm" includeIn="login">
                   <ns1:login />
               </jw:Card>
           </jw:View>
       </ex:initialView>
   </ex:Application>
   ```
   
   ***login.mxml***
   ```<?xml version="1.0" encoding="ISO-8859-1"?>
   <js:Container
   	xmlns:fx="http://ns.adobe.com/mxml/2009"
   	xmlns:mx="library://ns.apache.org/royale/mx"
       xmlns:js="library://ns.apache.org/royale/express"
       xmlns:jw="library://ns.apache.org/royale/jewel"
   	height="190" width="350" className="glassPods" initComplete="verif_sharedobject()">
   	<!-- height="190" width="350" styleName="glassPods" creationComplete="verif_sharedobject()"> -->
   	<fx:Script>
   		<![CDATA[
   			import mx.net.SharedObject;
   
   			private function verif_sharedobject():void{
   				console.log("Foo")
   				trace("Bar")
   				var sharedObject:SharedObject = SharedObject.getLocal("ftthmanager");
   				if (sharedObject.data.user != null){
   					login_login.text = sharedObject.data.user.name;
   					pass_login.text = sharedObject.data.user.pass;
   				}
   			}
   			private function save_sharedobject():void{
   				if(check_cookie.selected==true){
   					var sharedObject:SharedObject = SharedObject.getLocal("ftthmanager");
   					sharedObject.data.user = {name: login_login.text, pass: pass_login.text};
   					sharedObject.flush();
   				}
   			}
   		]]>
   	</fx:Script>
   	<jw:HGroup className="glassPanel" width="100%">
   		<jw:Label text="Identification" className="glassLabels"  id="titre"/>
   	</jw:HGroup>
   	<jw:Form id="loginForm" y="50" width="100%">
   		<jw:FormItem label="Login :" width="100%" id="label_login">
   		    <jw:TextInput width="160" id="login_login">
   				<jw:beads>
   					<jw:MaxNumberCharacters maxlength="40"/>
   				</jw:beads>
   			</jw:TextInput>
   		</jw:FormItem>
   		<jw:FormItem label="Mot de passe :" width="100%" id="label_pass" >
   		    <jw:TextInput width="160" id="pass_login" enter="save_sharedobject() parentDocument.verif_login(login_login.text,pass_login.text);">
   				<jw:beads>
   					<jw:PasswordInput />
   					<jw:MaxNumberCharacters maxlength="40"/>
   				</jw:beads>
   			</jw:TextInput>
   		</jw:FormItem>
   		<jw:FormItem label="Se souvenir de moi" width="100%" id="label_pass0">
   		    <js:CheckBox id="check_cookie" selected="true">
   		    </js:CheckBox>
   		</jw:FormItem>
   			<jw:Button text="Login" click="parent.verif_sharedobject()" id="bt_login" height="30" className="ButtonGrey"/>
   		<jw:Button text="triche" id="bt_login0" height="30" visible="false"/>
   	</jw:Form>
   </js:Container>
   ```
   
   
   ### As a reminder, I must find a way to call verif_login() which is in **index.mxml** from **login.mxml** when my button is clicked.
   
   As you can see we use Beads for some cases but for my problem I don't see how to implement your suggestion to this code. Jewel.Button doesn't have ParentDocumentBead in its beads list
   https://apache.github.io/royale-docs/component-sets/jewel/button
   
   I also found it's possible to add beads through actionScript:
   https://apache.github.io/royale-docs/features/strands-and-beads
   
   I made many link in my head reading the documentation helped by your previous post and I archieve few lines without error but I still have no idea about how to access parent method. Here some lines I tried after reading your post:
   
   ```
   		var buttonBead:IBead = bt_login.getBeadByType(IChild);
   		bt_login.addBead(buttonBead);
   		bt_login.verif_login(login_login.text,pass_login.text); // This line fails, it was just a test
   		var parentMethod:ParentDocumentBead = new ParentDocumentBead();
   ```
   
   If you have more explanation or idea about how to fix this
   
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org