A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Send variables form VB6 to AS3

  1. #1
    Senior Member
    Join Date
    Oct 2009
    Posts
    112

    Send variables form VB6 to AS3

    i've managed to send variables from AS3 to VB6 using fscommmand, but not the other way around. i've heard some people say the way to do this is using SetVAriable, but obviously SetVariable isn't supported by AS3.

    the next best thing seems to be ExternalInterface, but I am new to AS3 and i could use some help on writing this funciton!

    is anyone familiar wiht this?

    FOR STARTERS,
    i want to us ExternalInterface to send a variable from VB6 to a text field in my swf video. I already have the vb6 code, i just don't know how to do the code in the AS3 part.

    can someone please help with the code? (the instance name of my text field is svalue)
    THANKS

  2. #2
    Lifetime Friend of Site Staff Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    You can't send variables any more, you have to call an ActionScript function from the VB side and pass your data as arguments to that function. Look at how to use the ExternalInterface with JavaScript. In your case you will be using VB instead of JavaScript to call a function on the ActionScript side but the mechanism is the same and you will see examples of how to handle this in ActionScript where you're having trouble.

  3. #3
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    northcode, thanks.
    im not familiar with javascript, do u knwo where i could find a good example or should i just keep looking around on google?

    im trying something else now:
    vb6 can send and recieve variables to and from a *.txt file.

    i'm wondering if flash AS3 can do the same thing, i'm tyring to build a new swf to build this using exmaples CLASSROOM IN A BOOK but they're code is all scattered and complicated, because they want you to use all the files from the CD.

    im sure there is a simple code to load text into a text field from an external file, do u know the code for this?

  4. #4
    Lifetime Friend of Site Staff Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    Check out this tutorial.. http://blog.circlecube.com/2008/02/t...-communication

    You can use a text file to communicate one way (from VB to Flash) but Flash won't be able to write text files to send data back to VB. This solution would also be really slow.

  5. #5
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    ok that worked, but ur right it's really slow.

    obviously i can't ask u to do all the work for me, but do have u ever seen a solid example of ExternalInterface.addCallback, etc...because i havent!
    do u know anything about this particular event or how to use it?

    i looked at more that relate to javascript but it didnt help much, becasue i still don't know where to start when relating it to VB

    sorry for the hassle i appreciate all your help!

  6. #6
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    or is their a way to communicate using XML sockets? or would that be slower?
    i still have a feeling externalInterface will yield the best results

  7. #7
    Lifetime Friend of Site Staff Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    ActionScript 3 code to receive calls from VB

    Code:
    function FlashFunction(o:Object)
    {
       var r:String = "";
       for (var v in o)
          r += v + ":" + o[v] + "\r";
      // r is the argument list we were passed 
       return "FlashFunction was called"; // this goes back to VB
    }
    
    if (ExternalInterface.available)
       ExternalInterface.addCallback('FlashFunction', FlashFunction);
    VB code to call a Flash function called "FlashFunction" n SWF. The "FlashFunction" must be registered via ExternalInterface.addCallback on the Flash side before we can call it from VB.

    Code:
    Dim x As String
    x = "<invoke name=""FlashFunction"" returntype=""xml"">"
    x = x & "<arguments>"
    x = x & "<object>"
    x = x & "<property id='arg1'><string>value1</string></property>"
    x = x & "<property id='arg2'><string>value2</string></property>"
    x = x & "</object>"
    x = x & "</arguments>"
    x = x & "</invoke>"
    
    Dim r As String 
    r = ShockwaveFlash1.CallFunction(x)
    ' r is result passed back from Flash (XML in stirng format)
    MsgBox r, vbInformation, "FlashFunction called, result from Flash"
    To go the other way, just implement the ShockwaveFlash1.FlashCall event on the VB side and use ExternalInterface.call() to call out using whatever parameters you like. You don't have to register each function you want to call on the VB side. For example: ExternalInterface.call("VBFunction", "pi", 3.1415927). All calls go to the one FlashCall event in VB and you have to parse the mess of XML you get from Flash

    Last edited by Northcode; 10-05-2009 at 05:36 PM.

  8. #8
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    thanks thats exactly what i've been looking for!

    on the top line:

    function FlashFunction(o:Object)

    would i insert the function of what i want to happen when flash recieves a message from vb?

    if so, can I change the o:Object to e:Event?

    if so, then would i also change the (var v in o) and o[v]

    to

    (var v in e) and e[v]

    or am i looking at this wrong.....

  9. #9
    Lifetime Friend of Site Staff Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    The "FlashFunction" is a name I picked, you can call it whatever you like, just remember to change the name in ExternalInterface.addCallback too. You can add as many callback functions as you like or need.

    This a callback function, not an event handler so you get a generic Object as the parameter, not and Event object. I don't know what kind of odd things Flash might do if you declare the parameter as an Event object, but you can try it if you're feeling adventurous

  10. #10
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    ok i did get it to work but then it meant i was using fscommand to communicate one way, and external interface the other way.

    so now i have gone a different route altogether, using BINARY SOCKETS.

    iI have gotten this to work so no questions about that.

    I have a question about tracking an object..

    I have a slider that moves up and down on a rectangle. here is part of my code


    function sData(e:ProgressEvent):void{
    var d:String=s.readUTFBytes(s.bytesAvailable);
    d=d.charAt(0);
    trace(d);
    slider10.y=Number(d)*40;
    }

    import flash.events.MouseEvent;

    var bounds:Rectangle = new Rectangle(424.9, 37, 0, 320);

    var bounds is the rectangle that my slider is sliding up and down on, and in another part of hte code I have given this slider 8 positions on the rectnagle (320/40). is there a way to track this position?
    right now i have it tracked by slider10.y=Number(d)*40, but that's tracking it's position on the STAGE rather than the rectnagle, which is why I have to multiply by 40 to make it euqal numbers between 1 and 320 on the stage.

    this works, but is extrmeley inaccurate. it gives off numbers between 1 and 9 rather than 0 through 8, and it moves around funny on the Rectangle track.

    is there a way I can say slider10.POSITION ON Rectangle=Number(d)? (rather than slider10.y)

    i hope this made sense if not let me know and ill re-explain it lol

  11. #11
    Lifetime Friend of Site Staff Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    Using sockets for the basic communications isn't a great idea. It will be slow and it will trigger Windows Firewall for anyone who has it turned on. If your application isn't doing anything "networky" then triggering the firewall will be unexpected and make people suspicious. There's no reason you can't use ExternalInterface for communication in both directions. The other part of your question will likely get better attention in AS3 forum or general Flash help.

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