Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS3 in asp.net

Guest
Jan 17, 2013 Jan 17, 2013

Hi All,

I have an as3 project made in flash builder 4.6 that I want to include in asp.net project. In as3 there is an object which position I want to save in Database after button click in asp.net. There will be posibility to set 5 different positions. I will also have 5 buttons in asp.net to show saved position, and also a button which will invoke movement of object from first to last position. How can I achieve it?

TOPICS
ActionScript
6.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 20, 2013 Jan 20, 2013

it looks like your post in message 12 is a completely different topic.

you're now trying to communicate from asp generated buttons to an embedded flash file?  if yes, you would use the externalinterface class. in particular, you would use the addCallback method.

Translate
Community Expert ,
Jan 18, 2013 Jan 18, 2013

use the urlloader class to call your asp file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 18, 2013 Jan 18, 2013

But in what form should be variables send from asp.net? Could I use POST FORM, or something similar?

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.js" type="text/javascript"></script>
<script type="text/javascript">
     $(function () {
         $("#btnPayNow").click(function (event) {
             event.preventDefault();

             //construct htmlForm string
             var htmlForm = "<form id='myform' method='POST' action='http://localhost:49816/WebSite1/FlareZnamNew2.swf'>" +
                 "<input type='hidden' id='name' value='15' />" +
             "</form>";

             //Submit the form
             $(htmlForm).appendTo("body").submit();
         });
     });
</script>
            var urlRequest:URLRequest = new URLRequest("http://localhost:49816/WebSite1/CwiczeniaC2.aspx");
            var urlLoader:URLLoader = new URLLoader();
            urlLoader.dataFormat = URLLoaderDataFormat.TEXT; // default
            urlLoader.addEventListener(Event.COMPLETE, urlLoader_complete);
            urlLoader.load(urlRequest);
           
            function urlLoader_complete(evt:Event):void {
                testN = urlLoader.data;
                updateTextFields()
            }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 18, 2013 Jan 18, 2013

:

var urlRequest:URLRequest = new URLRequest("http://localhost:49816/WebSite1/CwiczeniaC2.aspx");
            var urlLoader:URLLoader = new URLLoader();

// you probably don't want this unless your asp page is parsing the sent string.  typically you use VARIABLES and the POST (or GET) method property of your urlrequest and you create a urlvariables instance to contain your data and use the data property of the request:

      //      urlLoader.dataFormat = URLLoaderDataFormat.TEXT;

urlLoader.dataFormat=URLLoaderDataFormat.VARIABLES;

urlRequest.method="POST";

var urlVariables:URLVariables=new URLVariables();

urlVariables.whatever=something;

// etc

urlRequest.data=urlVariables;
            urlLoader.addEventListener(Event.COMPLETE, urlLoader_complete);
            urlLoader.load(urlRequest);
           
            function urlLoader_complete(evt:Event):void {
                testN = urlLoader.data;
                updateTextFields()
            }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 18, 2013 Jan 18, 2013

So I made it like this since variable name value is 15

var _vars:Number

urlVariables.name=_vars;

but i'm getting an error:

The string passed to URLVariables.decode () must be encoded query string as a URL and must include the name / value pairs.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 18, 2013 Jan 18, 2013

what's being returned by your asp file?  (it needs to be name/value pairs.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 19, 2013 Jan 19, 2013

I found post with smilar problem but with strange solution:

http://www.aspmessageboard.com/showthread.php?230681-Passing-variables-to-Flash

How can I make a HTML POST instead of:

<&#37;response.write FormatDateTime(now(),0)%>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2013 Jan 19, 2013

use:

response.write "date_now="&FormatDateTime(now(),0)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 19, 2013 Jan 19, 2013

I got back with Variables TEXT. In my example it will be easier. I made a form post to send value to flash. Unfortunatly it doesn't work. I will give You all my code. After page load the value of TestN is "NaN" (I don't know why). After Submit it should be "nowe"

AS3 code:

        private var controls:TextField = new TextField();

        private var testN:Number = 0;

        public function FlareZnamNew2()

        {

            scene = new Scene3D(this);

            scene.registerClass( Flare3DLoader1 )

            scene.camera = new Camera3D();

            scene.camera.setPosition( 200, 200, -300 );

            scene.camera.lookAt( 0, 50, 0 );

            scene.addEventListener( Scene3D.COMPLETE_EVENT, completeEvent );

            var _vars:Number

            var urlRequest:URLRequest = new URLRequest("http://localhost:49816/WebSite1/Cwiczenia.aspx");

            var urlLoader:URLLoader = new URLLoader();

            urlLoader.dataFormat = URLLoaderDataFormat.TEXT;

            urlRequest.method="POST";

            urlLoader.addEventListener(Event.COMPLETE, urlLoader_complete);

            urlLoader.load(urlRequest);

                 }

        public function urlLoader_complete(e:Event):void {

            testN = e.target.data;

            updateTextFields()

        }

       

        public function updateTextFields():void

        {

            controls.htmlText =    "Model Position" + testN + newPosition2 +

                "3: Add boxes";

        }

ASP.NET:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="CwiczeniaC2.aspx.vb" Inherits="CwiczeniaC2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

    <object width="900" height="400" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="Object1" >

            <param name="src" value="FlareZnamNew2.swf" />

            <param name="allowFullScreen" value="true" />

            <param name="wmode" value="direct" />

            <embed src="FlareZnamNew2.swf" autostart="true" flashvars="init=yes&check=true" allowfullscreen="true" width="800" height="450"

                quality="autohigh" bgcolor="#000000" name="myMovieName" wmode="direct"/>

</object>

        <br />

        <br />

        <form id='myform' method='post' action='http://localhost:49816/WebSite1/FlareZnamNew2.swf'>

        <input type='hidden' id='name' value='nowe' />

        <input type="submit" value="Submit" />

        </form>

    </form>

</body>

</html>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2013 Jan 19, 2013

you're not sending any data from flash.  does your asp file need any data from flash?

if not, just make sure those are trusted files so flash allows you to access data across security sandboxes:  http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 19, 2013 Jan 19, 2013

Yes it should, but firstly I need to know if my submit form works. I would like to send from flash model position into sql database.

here is my function to send back data:

                               private function savevalue():void

                               {

                                               var PosH:Vector3D = hat.getDir();

                                               var PosHX:Number

                                               var PosHY:Number

                                               var PosHZ:Number

                                              

                                               var loader : URLLoader = new URLLoader(); 

                                               var request : URLRequest = new URLRequest("http://localhost:49816/WebSite1/MyService.asmx");

                                              

                                               request.method = URLRequestMethod.POST; 

                                               var variables : URLVariables = new URLVariables();

                                               variables.PosHX = PosH.x;

                                               variables.PosHY = PosH.y;

                                               variables.PosHZ = PosH.z;                          

                                               request.data = variables; 

                                              

                                               loader.addEventListener(Event.COMPLETE, on_complete); 

                                               loader.load(request); 

                               }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2013 Jan 19, 2013

i have no idea what the code in message 10 has to do with any of the other code you showed.

just show the actionscript and asp code you're using now and make sure you take care of the security sandbox issue.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 20, 2013 Jan 20, 2013

Maybe I will write what is the all issues. Flash Application is a part of a large Asp.Net project. There will be a model which user will be able to set position and save it in Database. There will be posibilty to save 5 different positions. Then user will be able to show every positions, and use "play" option where model will be moving from first to last position. So what I need to do is:

1. make a save button which will send information to flash to invoke savevalue().

        public function urlLoader_complete(e:Event):void {

            testN = e.target.data;

            if (testN == "nowe")

            {  

             savevalue()

             }

         }

     and then send back position variables and save it in asp.net DB

2. make 5 position buttons which will invoke getposition() function

           ....

           if (testN == "Pos1")

           {

           getposition1()

           }

3. make "play" button which will invoke play()

           if (testN == "play")

           {

           play()

           }

I would like to make those buttons in asp.net, because i will be able to send also a username from asp.net DB. Unless there is a better solution

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 20, 2013 Jan 20, 2013

it looks like your post in message 12 is a completely different topic.

you're now trying to communicate from asp generated buttons to an embedded flash file?  if yes, you would use the externalinterface class. in particular, you would use the addCallback method.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 20, 2013 Jan 20, 2013

I find some good examples, but in my case it doesn't work. What might be the reason?

as3:

public function FlareZnamNew2()

        {

                ExternalInterface.addCallback("sendTextFromHtml", getTextFromJavaScript);

                }

        public function getTextFromJavaScript(str:String):void {

            if (str == "nowe") {

                updateTextFields();

            }

        }

        public function updateTextFields():void

        {

            controls.htmlText =    "Model Position dziaÅ‚a prawidÅ‚owo" ;

        }

asp.net:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="CwiczeniaC2.aspx.vb" Inherits="CwiczeniaC2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

<script type="text/javascript">

    function getFlashMovie(movieName) {

        var isIE = navigator.appName.indexOf("Microsoft") != -1;

        return (isIE) ? window[movieName] : document[movieName];

    }

    function playMovie() {

        getFlashMovie("Object1").sendTextFromHtml("nowe");

        return true;

    }

</script>

    <form id="form1" runat="server">

    <div>

    <object width="900" height="400" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="Object1" >

            <param name="src" value="FlareZnamNew2.swf" />

            <param name="allowFullScreen" value="true" />

            <param name="wmode" value="direct" />

            <embed src="FlareZnamNew2.swf" autostart="true" flashvars="init=yes&check=true" allowfullscreen="true" width="800" height="450"

                quality="autohigh" bgcolor="#000000" name="myMovieName" wmode="direct"/>

</object>

        <br />

        <br />

        <input id="Button2" type="button" value="Save" onclick="playMovie();"/>


</form>

</body>

</html>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 20, 2013 Jan 20, 2013

I think it will be working. Im seeing for a while corect view, but after that the page is reloaded an it gets first value. But to invoke savefunction() it should work. Thanks for help. I was looking for a solution for 2 weeks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 20, 2013 Jan 20, 2013

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 22, 2013 Jan 22, 2013

Will You be able to help me with one more thing?

I would like to send with extarnalinterface few variables with an array. It doesn't work and I don't see where might be the problem.

ExternalInterface.addCallback("sendTextFromHtml", getTextFromJavaScript);

public function getTextFromJavaScript(str:String):void {

            var ara:Array = new Array(str);

            var zm:String = ara[0];

            if (zm == "nowe") {

                controls.htmlText =    "Model Position dziaÅ‚a prawidÅ‚owo" + ara[0] + ara[1] + ara[2] ;

            }

        }

Asp.net

   function playMovie() {

        getFlashMovie("Object2").sendTextFromHtml("nowe,send,ID");

        return true;

    }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2013 Jan 22, 2013

use:

ExternalInterface.addCallback("sendTextFromHtml", getTextFromJavaScript);

public function getTextFromJavaScript(str:String):void {

            var ara:Array = str.split(",");

            var zm:String = ara[0];

            if (zm == "nowe") {

                controls.htmlText =    "Model Position dziaÅ‚a prawidÅ‚owo" + ara[0] + ara[1] + ara[2] ;

            }

        }

Asp.net

   function playMovie() {

        getFlashMovie("Object2").sendTextFromHtml("nowe,send,ID");

        return true;

    }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 23, 2013 Jan 23, 2013

Thanks, a lot. That works.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2013 Jan 23, 2013

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 30, 2013 Jan 30, 2013

I'm stuck again with showing positions. I don't know where might be the problem. I made another button to show models position.

<input id="Submit2" type="submit" value="Pozycja 1"  onclick="playMovie2(); return false;"/>

I made a call to the same ExternalInterface.addCallback

    function playMovie2() {

        getFlashMovie("Object2").sendTextFromHtml("pos1," + ID);

        return false;

    }

then if array begins with "pos1" then it should call webservice to get data from database.

                        public function getTextFromJavaScript(str:String):void {

                                    ara = str.split(",");

                                    var zm:String = ara[0];

                                    zm2 = ara[1];

                                    if (zm == "nowe") {

                                                updateTextFields1();

                                                savevalue();

                                    }

                                    else if (zm == "pos1") {

                                                showvalue1();

                                                updateTextFields1();

                                    }

                          }

Then I call a webservice and wait for response.

              public function showvalue1():void

              {

                    ws = new WebService();

                    ws.connect("http://localhost:49816/WebSite1/MyService.asmx?WSDL");

                    ws.addEventListener(Event.COMPLETE, connected);

              }

              public function connected(e:Event):void {

                   

                    ws.showPos1(done, zm2);

              }


              public function done(serviceResponse:XML):void{

                    trace(serviceResponse)

          Test2 = serviceResponse.text();

                    updateTextFields1();

                }

              public function updateTextFields1():void

              {

                    controls.htmlText =       "Pozycja zapisana" + Test2;

                }

And here is the Webservice.

Imports System.Web.Services.Protocols

Imports System.Web.Script.Services

Imports System.Data

Imports System.Data.SqlClient

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.

<System.Web.Script.Services.ScriptService()> _

<WebService(Namespace:="http://todo.org/")> _

<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _

Public Class MyService

    Inherits System.Web.Services.WebService

    'Public r As String

    <WebMethod()> _

    <ScriptMethod(UseHttpGet:=True)> _

    Public Function showPos1(zm2 As Integer) As String

        Dim Conn As New System.Data.SqlClient.SqlConnection()

        Conn.ConnectionString() = ConfigurationManager.ConnectionStrings("znamConnectionString").ConnectionString

        Dim cmd2 As New SqlCommand()

        cmd2.CommandText = "Select PosH from EModel where EID=@EID and PosID=@PosID SELECT SCOPE_IDENTITY()"

        cmd2.CommandType = CommandType.Text

        cmd2.Connection = Conn

        Dim param3 As New SqlParameter("@EID", SqlDbType.NChar, 10)

        param3.Value = zm2

        cmd2.Parameters.Add(param3)

        Dim param4 As New SqlParameter("@PosID", SqlDbType.NChar, 10)

        param4.Value = 1

        cmd2.Parameters.Add(param4)

        Conn.Open()

        Dim result2 As String = cmd2.ExecuteScalar()

        Conn.Close()

        Return result2

    End Function

End Class

Data is saved correctly. I just can't get it back from DB.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 31, 2013 Jan 31, 2013

I checked everything. Call to an ExternalInterface works fine and also ASP.NET Webservice is giving right values. It must be something with Webservice function in AS3. I use alducente class to call webservice.

import alducente.*;

public var ws:WebService = new WebService();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 31, 2013 Jan 31, 2013
LATEST

I find the solution. I used urlloader.

              public function showvalue2():void{

                    var loader : URLLoader = new URLLoader(); 

                    var request : URLRequest = new URLRequest("http://localhost:49816/WebSite1/MyService.asmx/showPos1");

                   

          request.method = URLRequestMethod.POST; 

                    var variables : URLVariables = new URLVariables(); 

          variables.zm2 = zm2;             

          request.data = variables; 

                   

          loader.addEventListener(Event.COMPLETE, LoadXML); 

          loader.load(request); 

  }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines