User avatar
kevind
Intermediate
Intermediate
Posts: 475
Joined: Tue Jan 11, 2005 8:51 pm
Location: Vancouver, BC, Canada
Contact: Send private message

Java code help - nested variable updating

Mon Jan 17, 2011 12:47 pm

I am so close to fully understanding the code side of this. For example, the below code always gives me an error of null for id “zonepower”. The code works perfect if I rem out the zonepower line. I am trying to have buttons highlight on the fly if the suite16 zone power is on. I don’t get it, I have spans with unique ID’s of “zonepower1”, zonepower2 etc (have tried numerous variations) and all error. I have tried. the class comment line works so i figured using that as a model I would just add a line into the for loop to update the css zonepower just like the css comment. Does not work. It's got to be something simple....so close to having this figured out once and for all.

for (var i=1;i<=16;i++) {
id = $("ml__mlsuite16_room_" + right("000"+i,3) + "_power").innerHTML;
$("ml__mlsuite16_room_" + right("000"+i,3) + "_source_display").setAttribute("class", "comment"+id);
$("zonepower"+i).setAttribute("class", "zonepower"+id);
}

Or this variation


for (var i=1;i<=16;i++) {
id = $("ml__mlsuite16_room_" + right("000"+i,3) + "_power").innerHTML;
$("ml__mlsuite16_room_" + right("000"+i,3) + "_source_display").setAttribute("class", "comment"+id);
$("zonepower" + right("000"+i,3)).setAttribute("class", "zonepower"+id);
}


For this bit of code
<span id=”zonepower1” class=”zonepower{{mlsuite16_room_001_power”>

or this variation
<span id=”zonepower001” class=”zonepower{{mlsuite16_room_001_power”>

both the above cause a "null" error.

This section of HTML code works perfect with the for loop and the comment css tag is updated on the fly properly....
<span id="ml__mlsuite16_room_001_source_display" class="comment{{MLSuite16_Room_001_Power}}">{{MLSuite16_Room_001_Source_Display}}</span>
<span id="ml__mlsuite16_room_001_volume_absolute" class="comment{{MLSuite16_Room_001_Power}}">{{MLSuite16_Room_001_Volume_Absolute}}</span>

User avatar
AllonisDave
Founder
Founder
Posts: 11580
Joined: Fri Feb 07, 2003 8:56 am
Location: Newport Beach, CA
Contact: Send private message

Re: Java code help - nested variable updating

Mon Jan 17, 2011 2:49 pm

Kevin email me your current html file for that page.

bigDvette
Expert
Expert
Posts: 718
Joined: Thu Oct 12, 2006 1:19 pm
Contact: Send private message

Re: Java code help - nested variable updating

Mon Jan 17, 2011 3:42 pm

kevind,

I assume you have a span somewhere on your screen with an id of

ml__mlsuite16_room_001_power. If not, you will get a null for the innerHTML

User avatar
kevind
Intermediate
Intermediate
Posts: 475
Joined: Tue Jan 11, 2005 8:51 pm
Location: Vancouver, BC, Canada
Contact: Send private message

Re: Java code help - nested variable updating

Mon Jan 17, 2011 3:55 pm

Dave,

Email sent of my last rendition.

BigDvette

Yes

<span id="ml__mlsuite16_room_001_power" style="display: none;">{{MLSuite16_Room_001_Power}}</span>

bigDvette
Expert
Expert
Posts: 718
Joined: Thu Oct 12, 2006 1:19 pm
Contact: Send private message

Re: Java code help - nested variable updating

Mon Jan 17, 2011 4:06 pm

Ok, if what you are saying is when you execute this line

THis is jquery right?

Shouldn't there be a # sign in front of you variable like

$('#zonepower' + i)

User avatar
kevind
Intermediate
Intermediate
Posts: 475
Joined: Tue Jan 11, 2005 8:51 pm
Location: Vancouver, BC, Canada
Contact: Send private message

Re: Java code help - nested variable updating

Mon Jan 17, 2011 5:21 pm

Not using jQuery but after having a quick look at the jquery site I am going to re-think this. JQuery looks like a good idea.

bigDvette
Expert
Expert
Posts: 718
Joined: Thu Oct 12, 2006 1:19 pm
Contact: Send private message

Re: Java code help - nested variable updating

Mon Jan 17, 2011 5:25 pm

YOu might try putting your div in a var first

like zonedivstr = 'zonepower' + i

then use that

User avatar
kevind
Intermediate
Intermediate
Posts: 475
Joined: Tue Jan 11, 2005 8:51 pm
Location: Vancouver, BC, Canada
Contact: Send private message

Re: Java code help - nested variable updating

Mon Jan 17, 2011 5:28 pm

good idea. will try. Dave is also having a look. once all said and done, I will have to figure out how to streamline and speed things up.

bigDvette
Expert
Expert
Posts: 718
Joined: Thu Oct 12, 2006 1:19 pm
Contact: Send private message

Re: Java code help - nested variable updating

Mon Jan 17, 2011 5:51 pm

The best thing you can do to speed things up is to poll the server for variables more frequently. I did this by modifying dave's javascript files where the getvar request is sent to the server. I have 2 timeout variables. 1 used for after a command is sent (and when the screen is loaded) and 1 used when there isn't screen activity.

What I do is just have a loop counter and set the timout to .5 seconds for 5 iterations after a command is sent and then go back to 3 second updates. It made a huge difference in the "snappiness" of the screens.

To do this you will also need to make sure you give your timer a variable like

getvartimer = setTimeout(....)

Whenever a new command is sent, I cancel the timer and then restart it.

Has worked great so far.

User avatar
kevind
Intermediate
Intermediate
Posts: 475
Joined: Tue Jan 11, 2005 8:51 pm
Location: Vancouver, BC, Canada
Contact: Send private message

Re: Java code help - nested variable updating

Mon Jan 17, 2011 6:11 pm

setting a variable worked as you suggested. cool thanks! Still would like to know why though as other code in the loop is not set to a variable first unless this has something to do with id's that have "ml__" in them vs just an id we make up. I am wondering if Dave or someone can post on the WIKI some base rules for variable calling, nesting etc.

Once I get these fundemental questions in my head resolved it's off to the races. Everyday learning more. It's easy if you know the answer and the "why"

User avatar
kevind
Intermediate
Intermediate
Posts: 475
Joined: Tue Jan 11, 2005 8:51 pm
Location: Vancouver, BC, Canada
Contact: Send private message

Re: Java code help - nested variable updating

Mon Jan 17, 2011 6:29 pm

This is one variation of the code that is now working. At this time I am choosing just to update the style of the existing classes vs changing the classes themselves. Both ways work but it was easier this way. That being said, i had to rem out the line with webkit in it as this was causing a java error.

for (var i=1;i<=16;i++) {
id = $("ml__mlsuite16_room_" + right("000"+i,3) + "_power").innerHTML;
$("ml__mlsuite16_room_" + right("000"+i,3) + "_source_display").setAttribute("class", "comment"+id);
zonepowerstring = 'zonepower' + right("000"+i,3);
if (id == 'Off'){
document.getElementById(zonepowerstring).style.opacity = '0.8';
document.getElementById(zonepowerstring).style.border = '1px solid #000000';
document.getElementById(zonepowerstring).style.color = '#FFFFFF';
}
else {
document.getElementById(zonepowerstring).style.opacity = '1.0';
document.getElementById(zonepowerstring).style.border = '1px solid #6686ff';
document.getElementById(zonepowerstring).style.color = '#6686ff';
//document.getElementById(zonepowerstring).style.-webkit-box-shadow = '0px 0px 10px #FFFFFF';
}
//$(zonepowerstring).setAttribute("class", "audiozonepower"+id);
//$(zonepowerstring).setAttribute("class", "button_touch"+id);
}

except this line errors. Must be the "-" in webkit-box-shadow. Any ideas on how to get around this?

document.getElementById(zonepowerstring).style.-webkit-box-shadow = '0px 0px 10px #FFFFFF';

User avatar
kevind
Intermediate
Intermediate
Posts: 475
Joined: Tue Jan 11, 2005 8:51 pm
Location: Vancouver, BC, Canada
Contact: Send private message

Re: Java code help - nested variable updating

Mon Jan 17, 2011 6:41 pm

And solved that one too. Cool!

Wrong:
document.getElementById(zonepowerstring).style.-webkit-box-shadow = '0px 0px 10px #FFFFFF';

Right
document.getElementById(zonepowerstring).style.webkitBoxShadow = '0px 0px 10px #FFFFFF';

User avatar
kevind
Intermediate
Intermediate
Posts: 475
Joined: Tue Jan 11, 2005 8:51 pm
Location: Vancouver, BC, Canada
Contact: Send private message

Re: Java code help - nested variable updating

Mon Jan 17, 2011 6:57 pm

Like anything that while that code works, it threw a new monkey wrench in. Because the "on/offf" state is now being visually updated, a feature I had before no longer works and that is when you touched a button "hover" the border went white to give a visual as to what the user's current selected zone is. This is no longer there so I am suspecting the refresh is wiping that nice feature out.

Groan...can of worms ;(

Return to “MainLobby on the iPad”

Who is online

Users browsing this forum: No registered users and 1 guest