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 17:47:57 UTC

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

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