turn func to array?
- jeremyBass
- Newbie


- Joined: 29 Apr 2008
- Posts: 6
- Status: Offline
Hi ... I’m just starting out on really learning java scripting and flash interaction... got this little test function to work great... but I’m 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
mind you I’ve 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....
here is the JavaScript
Code: Select all
- <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’ve 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....
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
April 29th, 2008, 8:03 pm
- graphixboy
- Professor


- Joined: 11 Jul 2005
- Posts: 781
- Loc: Minneapolis, MN
- Status: Offline
Not exactly sure what your trying to do but it seems strange to try and turn a function into an array. By default they are two very different things. A function is a list of commands while an array is stored data.
Are you trying to take all the results and place them in an array? If so you would do something like
Are you trying to take all the results and place them in an array? If so you would do something like
//// Designer & Art Director for Interactive, Motion and 3D \\\\
Proof @ WhenImNotSleeping.com
Proof @ WhenImNotSleeping.com
- jeremyBass
- Newbie


- Joined: 29 Apr 2008
- Posts: 6
- Status: Offline
Oh I didn't mean to turn the function it's self into or the results... I was meaning to turn that function so it take an array..
this is one of my many tries
the real from field names are like this
m7feu_input_email_address = value one
m7feu_input_email_name = value two
so.....
but that didn't work... I was hoping to take m7feu_input_emal_address (the name of the form text box ) and put t var where it differs ... for all 200 items it'll be m7feu_input_*** ... I’m not even sure if that is allowed... if not I have not been able to replace the whole either... that is why I need help lol... I'm ok at php, html, even little actionscript... but i have a hard time with JS... thanks for helping..
this is one of my many tries
the real from field names are like this
m7feu_input_email_address = value one
m7feu_input_email_name = value two
so.....
Code: Select all
- var fields = ("email_address", "home_address", "name");
- 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 that didn't work... I was hoping to take m7feu_input_emal_address (the name of the form text box ) and put t var where it differs ... for all 200 items it'll be m7feu_input_*** ... I’m not even sure if that is allowed... if not I have not been able to replace the whole either... that is why I need help lol... I'm ok at php, html, even little actionscript... but i have a hard time with JS... thanks for helping..
- graphixboy
- Professor


- Joined: 11 Jul 2005
- Posts: 781
- Loc: Minneapolis, MN
- Status: Offline
ahhh ok I see what your trying to do. The nice thing is that javascript and actionscript are very similar so you would go about building your array in a similar fashion. I think you have a problem on two of the lines...
on your first line where you declare the array you need to use square brackets
then you refer to a value in an array with its numerical position starting with zero so in your example 0 = email, 1 = address, etc
so you would need code similar to this... for your text var which would make the value of text = document.htmlForm.m7feu_input_email_address.value
I'm not sure if this is the correct way to string content together in JS, its been a while since I've tried anything like that so you might just want to do something where you get two variables
on your first line where you declare the array you need to use square brackets
then you refer to a value in an array with its numerical position starting with zero so in your example 0 = email, 1 = address, etc
so you would need code similar to this... for your text var which would make the value of text = document.htmlForm.m7feu_input_email_address.value
I'm not sure if this is the correct way to string content together in JS, its been a while since I've tried anything like that so you might just want to do something where you get two variables
Code: Select all
- var path = document.htmlForm.m7feu_input_ + fields[0];
- var content = path.value;
//// Designer & Art Director for Interactive, Motion and 3D \\\\
Proof @ WhenImNotSleeping.com
Proof @ WhenImNotSleeping.com
- jeremyBass
- Newbie


- Joined: 29 Apr 2008
- Posts: 6
- Status: Offline
Not sure if what you suggested fixes my needs exactly... So the end goal is to pass an array of 200 values to flash form and have flash export the array of 200 back to the HTML form...
So I was thinking that this was more along what I need... I’m sure I didn't code this right but hopefully you get what i mean here...
if it helps here is the actionscript for the single value pass which worked great...
and the array attempt looks like this right now...
It's rough and i know the script is not 100% right but it's to pull the user input from 200 of a mix of these items:
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)
Thanks for helping... I'm learning, like i didn't know the js arrays need [] not ()
there is hope lol
So I was thinking that this was more along what I need... I’m sure I didn't code this right but hopefully you get what i mean here...
Code: Select all
- 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 + "";
- }
- }
if it helps here is the actionscript for the single value pass which worked great...
Code: Select all
- import flash.external.ExternalInterface;
- function getTextFromJavaScript(str:String):Void {
- PG_1.APP_Email.text = ""+str;
- }
- ExternalInterface.addCallback("sendTextToFlash",this,getTextFromJavaScript);
- function clickSend(eventObj:Object):Void {
- var jsArgument:String = PG_1.APP_Email.text;
- var result:Object = ExternalInterface.call("getTextFromFlash", jsArgument);
- PG_1.APP_Email.text = ""+result;
- }
- PG_1.send_button.addEventListener("click",clickSend);
and the array attempt looks like this right now...
Code: Select all
- 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;
- }
- }
It's rough and i know the script is not 100% right but it's to pull the user input from 200 of a mix of these items:
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)
Thanks for helping... I'm learning, like i didn't know the js arrays need [] not ()
- jeremyBass
- Newbie


- Joined: 29 Apr 2008
- Posts: 6
- Status: Offline
the working code:
well that worked... I think that would take care of all the javascript side of the form I was describing. I’ll 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…
Code: Select all
- <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>
well that worked... I think that would take care of all the javascript side of the form I was describing. I’ll 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…
- jeremyBass
- Newbie


- Joined: 29 Apr 2008
- Posts: 6
- Status: Offline
Hello, so i'm back... it truns out i was only a fifth of the way to a solution...
I'm have to make an arry for each type of componet and i'm have a little trouble on the yes not chack boxs...any ideas would be great...
this is what i have...
this puts/removes the checkboxes in an array
sets the click functions for the array
here is the yes no part
so continuing on my train of thought... I figured that it'd be best to try to make the yes no functions into the array style so that I could sort them and keep them in line to make it better to export... well as it goes I’m still having some fundamental problems with arrays... I'm trying to find the reasons why this won't work... and how to fix it... but i just keep coming up dry.... ideas..???
Ideas... could use a little help... i have this form to make and it's coming up soon... i really don't want to do this lol... it's not even my job lol... well thanks again for the help...
I'm have to make an arry for each type of componet and i'm have a little trouble on the yes not chack boxs...any ideas would be great...
this is what i have...
this puts/removes the checkboxes in an array
Code: Select all
- onEnterFrame(load)
- {
- _global.checkboxArray = new Array();
- _global.testIfSelected = function (t)
- {
- for(i=0;i<checkboxArray.length;i++)
- {
- if(checkboxArray[i]==t)
- {
- return i;
- }
- }
- return -1;
- }
- }
- function postGlobalCbArray():Void {
- var pos=testIfSelected(this.label,this.selected);
- if(this.selected == true)
- {
- if(pos == -1) checkboxArray.push(this.label,this.selected);
- }
- else
- {
- if(pos >=0) checkboxArray.splice(pos,1);
- }
- }
- /////////////////////////
- //////this is were i think one of the issues is<<<<<<<<<<<<<<<<
- //////////////////////////
- function RemoveGlobalCbArray():Void {
- var pos=testIfSelected(this.label,this.selected,this.value);
- if(this.selected == true)
- {
- if(pos == -1) checkboxArray.clear(this.label,this.selected,this.value);
- }
- else
- {
- if(pos >=0) checkboxArray.clear(this.label,this.selected,this.value);
- }
- }
sets the click functions for the array
Code: Select all
- for(j = 0; j < CBtypeArray.length; j++)
- {
- CBtypeArray[j].addEventListener("click",postGlobalCbArray);
- }
- function postGlobalCbArrayList():Void {
- for(j = 0; j < CBtypeArray.length; j++)
- {
- CBtypeArray[j].addEventListener("click",postGlobalCbArray);
- }
- }
- function RemoveGlobalCbArrayList():Void {
- for(j = 0; j < CBtypeArray.length; j++)
- {
- CBtypeArray[j].addEventListener("click",RemoveGlobalCbArray);
- }
- }
here is the yes no part
Code: Select all
- PG_2.prevWork._x = 2000;
- function onSelectPerv_EmploYes(checkbox) {
- if(PG_2.Perv_EmploY.selected == true) {
- PG_2.Perv_EmploY.selected = true;
- PG_2.Perv_EmploN.selected = false;
- postGlobalCbArrayList;
- PG_2.prevWork._x = 327.6;
- } else if (PG_2.Perv_EmploN.selected == true){
- PG_2.Perv_EmploN.selected = true;
- PG_2.Perv_EmploY.selected = false;
- RemoveGlobalCbArrayList;
- PG_2.prevWork._x = 2000;
- } else {
- PG_2.Perv_EmploN.selected = false;
- PG_2.Perv_EmploY.selected = false;
- RemoveGlobalCbArrayList;
- PG_2.prevWork._x = 2000;
- }
- }
- function onSelectPerv_EmploNo(checkbox) {
- if(PG_2.Perv_EmploN.selected == true) {
- PG_2.Perv_EmploY.selected = false;
- PG_2.Perv_EmploN.selected = true;
- RemoveGlobalCbArrayList;
- PG_2.prevWork._x = 2000;
- } else if (PG_2.Perv_EmploY.selected == true){
- PG_2.Perv_EmploN.selected = true;
- PG_2.Perv_EmploY.selected = false;
- PG_2.prevWork._x = 327.6;
- postGlobalCbArrayList;
- } else {
- PG_2.Perv_EmploN.selected = false;
- PG_2.Perv_EmploY.selected = false;
- RemoveGlobalCbArrayList;
- PG_2.prevWork._x = 2000;
- }
- }
- PG_2.Perv_EmploY.addEventListener("click",onSelectPerv_EmploYes);
- PG_2.Perv_EmploN.addEventListener("click",onSelectPerv_EmploNo);
so continuing on my train of thought... I figured that it'd be best to try to make the yes no functions into the array style so that I could sort them and keep them in line to make it better to export... well as it goes I’m still having some fundamental problems with arrays... I'm trying to find the reasons why this won't work... and how to fix it... but i just keep coming up dry.... ideas..???
Code: Select all
- var YES:Array = [{fId:Number(1), name:PG_2.Perv_EmploY.selected},
- {fId:Number(2), name:PG_2.RelativeEMPLO_Y.selected},
- {fId:Number(3), name:PG_2.EMPLO_Y.selected}];
- var NO:Array = [{fId:Number(1), name:PG_2.Perv_EmploN.selected},
- {fId:Number(2), name:PG_2.RelativeEMPLO_N.selected},
- {fId:Number(3), name:PG_2.EMPLO_N.selected}];
- var YNobj:Array = [{fId:Number(1), name:PG_2.prevWork.selected},
- {fId:Number(2), name:null},
- {fId:Number(3), name:null}];
- var YNobjVAL:Array = [{fId:Number(1), "327.6"},
- {fId:Number(2), "450"},
- {fId:Number(3), "250"];
- YES.sortOn("fId", Array.NUMERIC);
- NO.sortOn("fId", Array.NUMERIC);
- YNobj.sortOn("fId", Array.NUMERIC);
- YNobjVAL.sortOn("fId", Array.NUMERIC);
- //var YNarray:Array = [{name:YES}, {name:NO}, {name:YNobj}];
- trace("And the winners in descending order are: ");
- for(var i:Number=0; i<winOrder.length; i++){
- trace("name: " + YES[i]);
- trace("name: " + NO[i]);
- trace("name: " + YNobj[i]);
- trace("name: " + YNobjVAL[i]);
- trace("-----------------------------");
- }
- for (var {i:Number=0, j:Number=0, k:Number=0, l:Number=0}; {i<YES.length, j<NO.length, k<YNobj.length, l<YNobjVAL.length}; {i, j, k, l)++){
- YNobj[k]._x = 2000;
- function YES[i](checkbox) {
- if(YES[i].selected == true) {
- YES[i].selected = true;
- NO[j].selected = false;
- postGlobalCbArrayList;
- YNobj[k]._x = YNobjVAL[l];
- } else if (NO[j].selected == true){
- NO[j].selected = true;
- YES[i].selected = false;
- RemoveGlobalCbArrayList;
- YNobj[k]._x = 2000;
- } else {
- NO[j].selected = false;
- YES[i].selected = false;
- RemoveGlobalCbArrayList;
- YNobj[k]._x = 2000;
- }
- }
- function NO[j](checkbox) {
- if(NO[j].selected == true) {
- YES[i].selected = false;
- NO[j].selected = true;
- RemoveGlobalCbArrayList;
- YNobj[k]._x = 2000;
- } else if (YES[i].selected == true){
- NO[j].selected = true;
- YES[i].selected = false;
- YNobj[k]._x = YNobjVAL[l];
- postGlobalCbArrayList;
- } else {
- NO[j].selected = false;
- YES[i].selected = false;
- RemoveGlobalCbArrayList;
- YNobj[k]._x = 2000;
- }
- }
- }
- YES[i].addEventListener("click",YES[i]);
- NO[j].addEventListener("click",NO[j]);
Ideas... could use a little help... i have this form to make and it's coming up soon... i really don't want to do this lol... it's not even my job lol... well thanks again for the help...
Page 1 of 1
To Reply to this topic you need LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 7 posts
- Moderators: joebert, digitalMedia, UNFLUX
- Users browsing this forum: No registered users and 40 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum


