Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

How do I load available ports into comboboxes using flash/zinc3.0

I have a program that sends and receives data to a microcontroller, originally done in Visual Basic and I want to try to do the same thing using flash and Zinc.  Zinc has classes for comport but since im a little new to the syntax I'm looking for a little help to get started. by using this line (sample code from zinc) mdm.Dialogs.prompt(mdm.COMPort.ports); it displays the available ports properly (comma separated).  I want to load those into a combobox to select the port.

cbx1.addItem({label:"label", data:1}); // this works to add an item.

my question is can anybody provide a code snippet for getting these ports into the combobox (cbx1)?

I've tried a lot but keep getting errors in flash.

Edit:  It seems that mdm.COMPort.ports returns a string with all the ports separated by a comma.  COM1, COM2, COM3 etc..  So with that in mind how do I get this string into cbx1?  
0
Kawalski
Asked:
Kawalski
  • 2
  • 2
2 Solutions
 
CyanBlueCommented:
Um...  Something like this should work...
// FYI : not tested code...
var portData:String = mdm.COMPort.ports;   // COM1, COM2, COM3
var ports:Array = portData.split(", ");

for (var i:int = 0 ; i < ports.length ; i++)
{
   cbx1.addItem({label: ports[i], data: i});
}

Open in new window

0
 
KawalskiAuthor Commented:
Thank you for your response.  I tried something similiar that produced the same results.  It doesnt give  me any errors however it lists all the com ports, comma separated, as one item.  I had all but given up on it but I will keep trying.
0
 
CyanBlueCommented:
If I take the MDM stuff out of the picture, I can get it to work...

#1. Create a new FLA...
#2. Drag a comboBox component onto the stage and give it an instance name of 'cbx1'...
#3. Create a new Layer, attach the following code and test movie...
//var portData:String = mdm.COMPort.ports;
var portData:String = "COM1, COM2, COM3";
var ports:Array = portData.split(", ");

for (var i:int = 0 ; i < ports.length ; i++)
{
   cbx1.addItem({label: ports[i], data: i});
}

Open in new window

If that works for you, do this and paste the exact output so that we can see it...
trace("Com ports : " + mdm.COMPort.ports);

Open in new window

0
 
KawalskiAuthor Commented:
Well that was silly.  It worked as expected.  It turns out the whole problem was the space after the comma.

var ports:Array = portData.split(", "); // this does not work

var ports:Array = portData.split(",");  // this does work

Thank you so much for your help!
// This works perfectly
var portData:String = mdm.COMPort.ports;
var ports:Array = portData.split(",");

for (var i:int = 0 ; i < ports.length ; i++)
{
   cbx1.addItem({label: ports[i], data: i});
}

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now