SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Mar 2008
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    trun func to array?

    Hi ... I知 just starting out on really learning java scripting and flash interaction... got this little test function to work great... but I知 not sure how to turn it in to an array... I'm tried and tried and have getting no were... so i was think may-be some one could show me what a few of the ways to do it so i can see a good working model for me to go off of....

    here is the JavaScript
    Code:
    <script language="JavaScript">
     function getFlashMovie(movieName) {
      var isIE = navigator.appName.indexOf("Microsoft") != -1;
      return (isIE) ? window[movieName] : document[movieName];
     }
     function formSend() {
      var text = document.htmlForm.m7feu_input_email_address.value;
      getFlashMovie("v2.d").sendTextToFlash(text);
      
     }
     
     function getTextFromFlash(str) {
      document.htmlForm.m7feu_input_email_address.value = "" + str;
      return str + "";
     }
    </script>
    mind you I致e work hard to get this far... just have not been able to move ahead


    so the array example that I think I could get a good idea off of would be 4 items... unless some one think more makes a difference... I will be having a app to make in the near time that will have about 200 fields so ideas would be great... they all will be much like this...

    m7feu_input_email_address = value one
    m7feu_hidden_email_address = value one
    m7feu_input_email_name = value two
    m7feu_hidden_email_name = value two

    Please any help would be great thanks....

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure I understand totally but here's a guess:
    Code:
    <script language="JavaScript">
     function getFlashMovie(movieName) {
      var isIE = navigator.appName.indexOf("Microsoft") != -1;
      return (isIE) ? window[movieName] : document[movieName];
     }
     function formSend(id) {
      var theInput = data[id];
      var text = document.htmlForm.elements[theInput].value;
      getFlashMovie(id).sendTextToFlash(text);
      
     }
     
     function getTextFromFlash(id, str) {
      var theInput = data[id];
      document.htmlForm.elements[theInput].value = "" + str;
      return str + "";
     }
     
    var data = {
    	"v2.d" : "m7feu_input_email_address",
    	"v2.e" : "m7feu_hidden_email_address",
    	"v3.d" : "m7feu_input_email_name",
    	"v3.e" : "m7feu_hidden_email_name"
    };
    
    //example calls
    formSend("v2.d");
    test = getTextFromFlash("v3.d", "sometext");
    </script>
    Does that look right?

  3. #3
    SitePoint Member
    Join Date
    Mar 2008
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no... v2.d is th name of the flash movie... it does not change...

    the change is:
    m7feu_input_email_address,
    m7feu_input_phone,
    m7feu_input_name

    so I was thinking that it'd look like
    Code:
    var fields = {
    	"email_address",
    	"phone",
    	"name"
    };
     function getFlashMovie(movieName) {
      var isIE = navigator.appName.indexOf("Microsoft") != -1;
      return (isIE) ? window[movieName] : document[movieName];
     }
     function formSend() {
      var text = document.htmlForm.m7feu_input_[fields].value;
      getFlashMovie("v2.d").sendTextToFlash(text);
      
     }
     
     function getTextFromFlash(str) {
      document.htmlForm.m7feu_input_[fields].value = "" + str;
      return str + "";
     }
    but this didn't work out for me... but is the idea... not sure on the how end lol...thanks also i may have miss understude to so that don't mean you not right... i woun't know 100%... i'm know 90% at this point lol

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var fields = [
    	"email_address",
    	"phone",
    	"name"
    ];
    
     function formSend() {
       for (var i=0; i < fields.length; i++) {
         var text = document.htmlForm.elements["m7feu_input_" + fields[i]].value;
         getFlashMovie("v2.d").sendTextToFlash(text);
        }
      }
    something like that?

  5. #5
    SitePoint Member
    Join Date
    Mar 2008
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks i'll give it a try... someone else suggested

    Code:
    var fields = ['email_address', 'home_address', 'name']; 
     
    function formSend(){ 
    for(var i:Number = 0; i < fields.length; i++) { 
    var text = document.htmlForm.m7feu_input_ + fields{i] + .value; 
    getFlashMovie("v2.d").sendTextToFlash(text); 
     } 
    } 
     
    function getTextFromFlash(str) 
    for(var i:Number = 0; i < fields.length; i++) { { 
    document.htmlForm.m7feu_input_ + fields{i] + .value = "" + str; 
    return str + ""; 
    } 
    }
    Is this right??

    When it come down to it the whole point is to pass an array of 200 values from a flash based form to a HTML form ... back and forth through two buttons in flash... those four types of inputs in flash to text fields in HTML

    the AS in case it helps:

    this is an atemp and not working yet... but trying
    Code:
    import flash.external.ExternalInterface;
    var fields:Array = ["PG_1.APP_Email", "PG_1.APP_Name", "PG_2.APP_home_address"];
    PG_1.send_button.addEventListener("click", clickSend);
     
    function getTextFromJavaScript(str:String):Void {
    for(var i:Number = 0; i < fields.length; i++)
    {
     fields[i].text = "" + str;
    }
    }
     
     
    function clickSend(eventObj:Object):Void {
    for(var i:Number = 0; i < fields.length; i++)
    {
     var jsArgument:String = fields[i].text;
     var result:Object = ExternalInterface.call("getTextFromFlash", jsArgument);
     fields[i].text = "" + result;
    }
    }
    the four types examples

    PG_1.APP_Email.text <TextInput <<< i know this is right
    PG_1.APP_Yes.Boolean <CheckBox? <<< not sure
    PG_1.APP_States.selectedItem <ComboBox? <<< not sure
    PG_1.APP_Email.selectedItem <DataGrides? <<< not sure( a row of data ie: Item id, Item Name, Item Date ect)


    Again thank you for the learning help

  6. #6
    SitePoint Member
    Join Date
    Mar 2008
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    --jimfraser, well that worked... I think that would take care of all the javascript side of the form I was describing. I値l be bark if I learn of anything new to add like the AS side of this good to share thoroughly but never not at all If you have any ideas or tips that would be great thanks

    the working code:
    Code:
    <script language="JavaScript">
     function getFlashMovie(movieName) {
      var isIE = navigator.appName.indexOf("Microsoft") != -1;
      return (isIE) ? window[movieName] : document[movieName];
     }
     var fields = ['email_address', 'home_address', 'name']; 
     
    var fields = [
    	"email_address",
    	"phone",
    	"name"
    ];
    
     function formSend() {
       for (var i=0; i < fields.length; i++) {
         var text = document.htmlForm.elements["m7feu_input_" + fields[i]].value;
         getFlashMovie("v2.d").sendTextToFlash(text);
        }
      }
    
    function getTextFromFlash(str) {
      for (var i=0; i < fields.length; i++) { 
    document.htmlForm.elements["m7feu_input_" + fields[i]].value = "" + str; 
    return str + ""; 
    } 
    }
    </script>


Bookmarks

Posting Permissions

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