Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a variable from Flash into an ASP.net MultiView, how?

Status
Not open for further replies.

bananasbananas

IS-IT--Management
Apr 26, 2006
19
0
0
GB
This is one for Flash and ASP.net guys:

I've made a flash map with clickable (buttons) Postcode areas. Wehn the user makes a selction I want the postcode to be passed into an ASP.net page where the all the details relating to that postcode will be pulled from the database.
i want the results to display alongside the map so as to keep the site neat and simple. So i have created a multiview, View1 displays Current site News, View2 displays the results of a search bar i have implemented just below the site banner. I want View3 to display results from the Map- what is the code I use in Flash to do this?

Maybe there is a better way?

Thanks in advance.
 
loadVars.sendAndLoad

So in flash the code for your map button would be something like:
Code:
buttonName.onRelease = function() {
	sendVars = new LoadVars();
	sendVars.var1 = mapVariable;

	receiveVars = new LoadVars();
	receiveVars.onLoad = function(success) {
		if (success) {
			//do stuff
		} else {
			trace("error");
		}
	};
	sendVars.sendAndLoad("[URL unfurl="true"]http://localhost/aspxpage.aspx",[/URL] receiveVars, "POST");
};

You can do it with only one LoadVars() object, but my personal preference is to do it with two, one for send and one for receive.

Your .NET page should take the variables and respond with name/value pairs. Example:

Code:
dim correctVar as string = request("var1")
if correctVar = "value" then
    response.write "&reply=OK"
end if

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
thanks alot for your help, I was wondering if you could help me just a little more though.

Here is the code I have used in Flash, for a button called "b2" - the postcode variable is incidentally 'B2' also ;-).

-------
on (release) {
b2.onRelease = function() {
sendVars = new LoadVars();
sendVars.var1 = B2;

receiveVars = new LoadVars();
receiveVars.onLoad = function(success:Boolean) {
if (success) {
//do stuff
} else {
trace("error");
}
};
sendVars.sendAndLoad("default.aspx",receiveVars,"POST");
};
}
------

I was getting errors from Flash - it was telling me the coee needs to be in an "on" event so I added "on Release". not sure if that's whats causing my problem now, as the code doesnt appear to be run when I click the B2 button.

Supposing we got the Flash code to work, my ASPX page code looks as follows:

------

<asp:View ID="View1" runat="server">
<script runat="server">

Public Sub Method()
Dim correctVar As String = Request("var1")
If correctVar = "B2" Then Response.Write("&reply=OK")
End Sub

</script>
</asp:View>

------
I had to alter your code to the above, not sure if THIS is causing my problems.

I've got a feeling we(you) can crack this ! Thanks again.
 
If the code is actually on the button (which it appear it is) then you would remove the b2.onRelease part of the code. So it would be:

Code:
on (release) {
    sendVars = new LoadVars();
    sendVars.var1 = B2;

    receiveVars = new LoadVars();
    receiveVars.onLoad = function(success:Boolean) {
        if (success) {
            //do stuff
        } else {
            trace("error");
        }
    };
    sendVars.sendAndLoad("default.aspx",receiveVars,"POST");
};

I'm not sure how that code will react to using the asp:view object. I guess we'll see. What version of VS are you using?

Hope that gets it for you.

Wow JT that almost looked like you knew what you were doing!
 
Good stuff pixl8r that got the Flash code working. It looks for the page when i click the button, problem is, as you guessed, it isnt passing the variable to the asp:View object.

I'm using VWD 2005 Express

If you come up with any ideas don't hesitate to tell me! I'll try fidling with the code on my ASPX page..

I'm thinking if I put some scripting- similar to what you suggested- into the header, that looks for any Variable called "var1" and then passes that into my View somehow I think i'll be onto a winner. Additional problem is activating my View when it receives the variable. Anyhoo thanks for now!
 
For the .NET piece the code needs to be in the page load Sub. I haven't actually used the express edition, so I'm not sure how limited you are.

Wow JT that almost looked like you knew what you were doing!
 
K well this is my code so far:
---------------
Sub Page_Load(ByVal Src As Object, ByVal Args As CommandEventArgs)

Dim correctVar As String = Request("var1")
If correctVar = "B2" Then


Select Case (Args.CommandName)
Case "View1"
View_Main.SetActiveView(View1)
End Select
Label1.Text = "The postcode is " & correctVar & "."
End If


End Sub
----------------

My Multiview is called "View_Main"

All i got in my View code is:

----------
<asp:View ID="View1" runat="server">

<asp:Label id="Label1" Runat="Server"/>

</asp:View>
-----------

 
I also tinkered with the Flash code and altered the "default.aspx" to "default.aspx?var1="

Since I don't know if your code tells it to do that anyway.
 
Acually it looks like you are trying to do something different from what I understood. I though you were trying to display the information returned from .NET in the Flash movie, but it appears that isn't correct. You are trying to display the information from Flash in the MultiView "view3" right?

You will not be able to do that with the code I provided. In fact you can't do it with the server side code at all. The page will have to post back for that to work and you would lose state. You would have to use javascript and update the view client side.

Code:
on(release){
    getURL("javascript:updateView('b2');");
}

place a div in view 3 called something like 'view3Div' and then add your javascript function
Code:
 <script language=javascript>
    function updateView(i){
		var target 
		target = document.getElementById('view'+ i +'Div');
		if (confirm(target)){
		target.innerHTML = "Hello World";
		}
    }
		</script>

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
thanks for that , I have only just got back onto this project - i'm overloaded with work, I'd love to get that functioning so I can move on!

I changed the flash code on the button, and I created a Div in View 3 and added the code to the beginning of the page. Now when the user clicks on the button I get a popup box saying "Null". Thats it!
Not sure but maybe I need to create a way of calling ASP.net code from Flash rather than javascript as it doesn't appear to be finding the View in Multiview. Also maybe I need to add code in that Javascript code of yours that activates the View before trying to find it.. saying that I tried calling the default active view with your code and it still gave me a Null popup.
Thanks alot for all your help, I'm thinking if you can't do it no one can! I might have to find another solution to this. Mark
 
Gotta mention the variations on the code I tried:

My Multiview = Main_View
My View I want to display result in = View3
Div in View3 = View3Div

-----
your code:
target = document.getElementById('view'+ i +'Div');

Variations I tried:
target = document.getElementById('Main_View.View3.View3Div');

target = document.getElementById('View3Div');

All give Null popup
 
I should have mentioned that. The view has to be active for the javascript to work.

My code requires you to pass the variable for the number (I assume you are doing this). In no case will this code work if the view is not active. Fact is a view is not rendered (in HTML) at all if it isn't active.

You can call the server side code from flash, but when you do the whole page will post back and your flash movie will reload.

You may want to look into using an iFrame to contain your Flash movie.

Wow JT that almost looked like you knew what you were doing!
 
OK right so if I go ahead and write some ASP code that activates the view and then performs your javascript code, i assume this would work.

"My code requires you to pass the variable for the number (I assume you are doing this)."
Sorry I'm not sure I understand you, I am currently just using your code as is. I assume your code takes the variable "b2" and assigns it to the letter "i". If this is so could you expand on what this line is doing please:

document.getElementById('view'+ i +'Div');

My understanding is that you are asking the javscript to find the document element Viewb2div. If this is so i would need to create an element to match that in my HTML, and at this moment that isn't the case.
The id of my Element is always going to be 'View3Div' surely?
 
Then in your case you would pass "3" instead of "b2".

Wow JT that almost looked like you knew what you were doing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top