dcsimg
A Flash Developer Resource Site

Results 1 to 1 of 1

Thread: help with simplifying code

  1. #1
    Member
    Join Date
    Apr 2010
    Posts
    50

    help with simplifying code

    I am working on a web editing page and need help simplifying some code. I used a template to write/read code from text files but it is acting up ( I modified it for multiple files instead of one, and it already seemed a bit redundant from the start). I am a bit unclear on how the code functions and sneakyimp suggested that I might need to streamline it as the code might not be working properly.

    I would appreciate the help if anyone could check out my code below and give me a better version of it.

    Code:
    //Scroll 1
    scroll1.visible = (text_txt.maxScrollV > 1);
    text_txt.addEventListener(Event.CHANGE, textchange);
    function textchange(e:Event):void {
    	scroll1.visible = (text_txt.maxScrollV > 1); }
    //Scroll 2
    scroll2.visible = (text_txt.maxScrollV > 1);
    text_txt2.addEventListener(Event.CHANGE, textchange2);
    function textchange2(e:Event):void {
    	scroll2.visible = (text_txt2.maxScrollV > 1); }
    //Scroll 3
    scroll3.visible = (text_txt.maxScrollV > 1);
    text_txt3.addEventListener(Event.CHANGE, textchange3);
    function textchange3(e:Event):void {
    	scroll3.visible = (text_txt3.maxScrollV > 1); }
    //Scroll 4
    scroll4.visible = (text_txt.maxScrollV > 1);
    text_txt4.addEventListener(Event.CHANGE, textchange4);
    function textchange4(e:Event):void {
    	scroll4.visible = (text_txt4.maxScrollV > 1); }
    //Scroll 5
    scroll5.visible = (text_txt.maxScrollV > 1);
    text_txt5.addEventListener(Event.CHANGE, textchange5);
    function textchange5(e:Event):void {
    	scroll5.visible = (text_txt5.maxScrollV > 1); }
    //global imports
    import flash.events.*;
    import flash.net.URLLoader;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLRequest;
    stop();
    
    //Input1-H
    var variables:URLVariables = new URLVariables();
    var varSend:URLRequest = new URLRequest("writeH.php");
    var varLoader:URLLoader = new URLLoader;
    varSend.method = URLRequestMethod.POST;
    varSend.data = variables;
      
    //Input2-E
    var variables2:URLVariables = new URLVariables();
    var varSend2:URLRequest = new URLRequest("writeE.php");
    var varLoader2:URLLoader = new URLLoader;
    varSend2.method = URLRequestMethod.POST;
    varSend2.data = variables2;
     
    //Input3-M
    var variables3:URLVariables = new URLVariables();
    var varSend3:URLRequest = new URLRequest("writeM.php");
    var varLoader3:URLLoader = new URLLoader;
    varSend3.method = URLRequestMethod.POST;
    varSend3.data = variables3;
    
    //Input4-A
    var variables4:URLVariables = new URLVariables();
    var varSend4:URLRequest = new URLRequest("writeA.php");
    var varLoader4:URLLoader = new URLLoader;
    varSend4.method = URLRequestMethod.POST;
    varSend4.data = variables4;
    
    //Input5-S
    var variables5:URLVariables = new URLVariables();
    var varSend5:URLRequest = new URLRequest("writeS.php");
    var varLoader5:URLLoader = new URLLoader;
    varSend5.method = URLRequestMethod.POST;
    varSend5.data = variables5;
    
    //text1
    
    var url:String = "H.txt";
    var loadit:URLLoader = new URLLoader();
    loadit.addEventListener(Event.COMPLETE, completeHandler);
    loadit.load(new URLRequest(url));
    
    function completeHandler(event:Event):void
    {
    text_txt.text = event.target.data as String;	
    }
    
    //text2
    var url2:String = "E.txt";
    var loadit2:URLLoader = new URLLoader();
    loadit2.addEventListener(Event.COMPLETE, completeHandler2);
    loadit2.load(new URLRequest(url2));
    
    function completeHandler2(event:Event):void
    {
    text_txt2.text = event.target.data as String;	
    }
    
    
    //text3
    var url3:String = "M.txt";
    var loadit3:URLLoader = new URLLoader();
    loadit3.addEventListener(Event.COMPLETE, completeHandler3);
    loadit3.load(new URLRequest(url3));
    
    function completeHandler3(event:Event):void
    {
    text_txt3.text = event.target.data as String;	
    }
    
    //text4
    var url4:String = "A.txt";
    var loadit4:URLLoader = new URLLoader();
    loadit4.addEventListener(Event.COMPLETE, completeHandler4);
    loadit4.load(new URLRequest(url4));
    
    function completeHandler4(event:Event):void
    {
    text_txt4.text = event.target.data as String;	
    }
    
    //text5
    var url5:String = "S.txt";
    var loadit5:URLLoader = new URLLoader();
    loadit5.addEventListener(Event.COMPLETE, completeHandler5);
    loadit5.load(new URLRequest(url5));
    function completeHandler5(event:Event):void
    {
    text_txt5.text = event.target.data as String;	
    }
    
    
    //button click
    bt_sub.buttonMode = true;
    bt_sub.addEventListener(MouseEvent.CLICK, ValidateAndSend);
    
    
    function ValidateAndSend(event:MouseEvent):void
    
    {  
        gotoAndPlay(2);
         variables.wootext = text_txt.text;
    	 varLoader.load(varSend);
    	 variables2.wootext2 = text_txt2.text;
    	 varLoader2.load(varSend2);
    	 variables3.wootext3 = text_txt3.text;
    	 varLoader3.load(varSend3);
    	 variables4.wootext4 = text_txt4.text;
    	 varLoader4.load(varSend4);
    	 variables5.wootext5 = text_txt5.text;
    	 varLoader5.load(varSend5);
    	 completeHandler(null);
    	 completeHandler2(null);
    	 completeHandler3(null);
    	 completeHandler4(null);
    	 completeHandler5(null);
    }
    Last edited by unknownelementx; 08-22-2010 at 05:34 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center