Notifications
Clear all

[Closed] need dotNet example of embedding SWF movies in rollouts

hi,
I am in need of a maxscript example on how to use Flash .swf files using dotNet. The reason for that is that already existing tutorials using activeX do not work with 64bit windows because the shockwave flash activeX component is not available in 64 bit windows releases. I have read however that dotNet is the way to go with 64bit compatibility.

A little background, I basicly need it for this tool I am working on:

http://boards.polycount.net/showthread.php?t=63675
Its a MZP file that temporarily extracts itself and launches a maxscript panel with a Flash movie in it. The panel can be customized and extended with any maxscript files that are stored in a folder inside the MZP file. I used Flash to create a full dynamic (liquid layout) menu that supports lots of different display modes and even Unicode (e.g Chinese, Japanese,… labels). All the maxscripts to be evaluated are send back to maxscript and executed there.

The big problem however is that right now it does not work with 64bit which is why I want to get it working with dotNet within maxscript.

what I have is basicly what comes with the 3dsmax help and uses activeX instead of dotNet:

rollout rFlash "TexTools 2.0"( 
	activeXControl flash "{D27CDB6E-AE6D-11CF-96B8-444553540000}" pos:[0,0] width:96 height:220  align:#left
	on flash FSCommand arg1 arg2 do(
		print("FScommand: "+arg1 +" / "+arg2);
	)
	on rFlash resized newSize do(
		flash.size = newSize;
	)
	on rFlash open do( 
		flash.movie = "c:/test.swf";
		flash.movie = "c:/test.swf"; -- need to load 2nd time sometimes
	)
)
CreateDialog rFlash 96 220 pos:[320,100] style:#(#style_titlebar,#style_resizing,#style_sysmenu,#style_toolwindow);

but when I was looking for a examples using dotNet I noticed that they all used the default microsoft forms (table, list, images, textfields,dx,…) but to my disadvantage not a single flash or similar example.

Further researching brought me to this microsoft page
Hosting ActiveX in dotNet using Component Object Model (COM)
http://msdn.microsoft.com/en-us/library/aa446515.aspx
but I dont have that kind of IT background so I dont know how and if it is even possible to apply this to maxscript?
So I already tried extracting the SWF dll from the IE plugin for XP/Vista/Win7 plugin that should be booth 32 and 64 bit – but I cant load it as assembly using

DotNet.LoadAssembly "NPSWF32.dll"

maybe someone can help me out with this because I don’t know any further right now :shrug:

13 Replies

for my bad luck , i’m on a laptop far from home and with 32bit only

now if i get what you mean , you need to make a swf file plays on a winForms ?

if this is the case


  the_form = dotnetobject "maxCustomControls.maxForm"
  the_Browser = dotnetobject"System.windows.forms.webbrowser"
  the_Browser.location = dotnetobject "System.Drawing.point" 10 30
  the_Browser.url =dotnetobject "System.uri" "http://www.bemboszoo.com/Bembo.swf"
  -- OR a Local File At your HD  "c:/temp/flash.swf"
  
  
  the_form.controls.add(the_Browser)
  the_form.show()
  

edit
yupech , nothing to be sorry about , please keep posting code

Edit: Sorry Mohab, I only noticed you replied after submitting my post…

Hi,

To embend a SWF with a .NET control in a rollout you have just to create a WebBrowser control (Enables the user to navigate Web pages) and set it current content (file or html source) to use a SWF:

(
	rollout WebBrowserSWF "WebBrowser SWF" width:400 height:500
	(
		dotNetControl webBrowser "System.Windows.forms.WebBrowser" pos:[10,10] width:380 height:480
		
		on WebBrowserSWF open do
		(
			webBrowser.Navigate(dotNetObject "System.Uri" "http://www.cgsociety.org/")
			-- Also take a look at webBrowser.DocumentText to set HTML contents of the page
		)
	)
	
	createDialog WebBrowserSWF
)

This is also the best way to host mov files for example.

there is a 64bit internet explorer version installed on every windows 64 version, if it works with flash, then it should be good, since max uses internet explorer.

but i had no luck yet finding a working flash 64 plugin…didn’t try recently though…

thanks for the replies so far, but…
how do I then send and receive arguments through the FScommand interface? Just displaying Flash wont do it for me alone- I need to
1.) pass over variables (Flash Vars) those could be perhaps done by dynamicly generating the HTML template that holds the SWF – but a more direct way would be nicer
2.) receive variables back in mxs vis FScommand. And this I believe might be a bit more difficult as the browser is in between the 2 platforms beeing:
mxs <-> browser <-> flash

So do any of you guys have some examples with Javascript and alike to send variables from HTML back to MXS?

oh and thanks for the examples and ideas so far

never mind, got myself already a working example:
http://forum.cgcharacter.com/showpost.php?p=5303203&postcount=265

for now it works good enough

its a dead link, does anyOne have a link to AS -> Max function calling using dotNet?

because some funny admin changed the server names, just swap the domain with the one we are on here:
http://forums.cgsociety.org/showpost.php?p=5303203&postcount=265

I posted about my stuff that is related to this on polycount:
http://boards.polycount.net/showthread.php?t=63675
I used JS and html as interface inbetween

thx m8 :wavey:

question: how do you press that pseudo button from AS?

1 Reply
(@renderhjs)
Joined: 11 months ago

Posts: 0

well there is a javascript file and you can trigger that JS file from within flash using the navigate to URL

var script:String = "toMaxScript(\"" + code + "\");";
var myURL:URLRequest = new URLRequest("javascript:" + script + "");
navigateToURL(myURL,'_self');//

‘toMaxScript’ again is a function written in Javascript that sends stuff to maxscript, it looks something like this:

<html>
<head>
<script>
//maxscript functions
function fromMaxScript(){
	alert('received: ' + '222'); 
}
function toMaxScript(codeString){
	var time = new Date();
	window.external.text=codeString+"#"+String(time.getTime());//add a unique timestamp at the end
	//window.external.text="anything...";
}
</script>
</head>

and in maxscript I embed that html file with its embedded javaScript functions like this:

rollout rFlash "MZP/rs 64" width:540 height:600(
	-------------------------------
	local baseURL = (pathConfig.GetDir #temp)+"\\mzpRucksack";
	local findAndReplace;
	-------------------------------
	function findAndReplace txt a b =(
		local cnt = txt.count;
		for i = 1 to cnt do(
			if txt[i] == a then(
				txt = replace txt i 1 b;
			)
		)
		return txt;
	)
	-------------------------------
	dotNetControl web "System.Windows.Forms.WebBrowser" pos:[0,0] width:120 height:220 	dotNetControl exec "System.Windows.Forms.Textbox" pos:[0,0] visible:false --hidden textbox that will hold commands passed from javascript
	-------------------------------
	on rFlash open do( 
		--web.IsWebBrowserContextMenuEnabled = dotnetobject "System.Boolean" false;--disable context menu
		web.ScrollBarsEnabled = dotnetobject "System.Boolean" false;--no scrollbars!!
		web.ObjectForScripting = exec;

		local url = baseURL+"\\sys\\wrapper.htm";
		
		-- read out the HTML file and modify it
		local html ="";
		local file = openFile url mode:"rt";
		if (file != undefined)then(
			seek file #eof;
			local lngth = filepos file;
			seek file 0;
			html = readChars file lngth errorAtEOF:false;
			eof file;
			try(close file)catch()
			
			
			--get the files that are within the folder structure of the extracted MZP
			local filesString = "";
			local rootFiles = getDirectories (baseURL+"\\*");--getFiles
			local export = "";
			for i=1 to rootFiles.count do(
				local pth = pathConfig.convertPathToRelativeTo rootFiles[i] baseURL;
				pth = trimLeft (findAndReplace pth "\\" "/") "./";
				if (pth != "sys/")then(
					filesString+=pth;--get rid of the .\ at the beginning
					local subFiles = getFiles (rootFiles[i]+"\\*");
					for j=1 to subFiles.count do(
						local item = pathConfig.convertPathToRelativeTo subFiles[j] rootFiles[i];
						item = trimLeft item ".\\";
						filesString+=item;
						if (j < subFiles.count)then(
							filesString+="*"
						)
					)
					if (i < rootFiles.count)then(
						filesString+="?"
					)
				)
			)
			--print(">> 
"+filesString);
			
			html = substituteString html "{files}" filesString;
			local save_url = baseURL+"\\sys\\wrapper_generated.htm";
			
			file = createFile save_url;
			if (file != undefined)then(
				format "%
" html to:file;--write to the string file
				try(close file;)catch();
				
				local neturl = dotNetObject "System.Uri" ("file://" +save_url);
				web.Navigate neturl;
				web.Navigate neturl;

			)else(
				print("error, cant write htm file on disc");
			)
		)else(
			print("error, cant find htm template on disc");
		)
			
		
	)
	-------------------------------
	on exec TextChanged e do( --once we get a command, execute it. Don't try this at home.
		local elements = filterString (exec.text) "#";
		
		if (elements.count >= 2)then(--single element
			local code  = elements[1] as string;
			code = findAndReplace code "'" "\"";--just to be sure
			
			try(
				execute code;
				print("execute: "+code);
			)catch(
				format "could not execute:
% 
" code;
			);
		)
		--print(">> execute :..."+elements[1] as string+" / "+exec as string+"/ "+e as string);
	)
	-------------------------------
)

the trick is to change the html document using javascript and watching for that in maxscript using:
on exec TextChanged.
At first I had a much easier version working with just activeX but since activeX pretty much is dead on 64 bit and Vista+ windows generations I was forced to find a way with dotNet.

 PEN

Are you doing all this to just get a dynamic UI? Why not just do this all in DotNet and don’t use Flash at all? Or am I missing something? Sounds to me like it is taking the long road around to get to the final result.

1 Reply
(@renderhjs)
Joined: 11 months ago

Posts: 0

I don’t have the background experience of c, c# dotNet and alike to code with but instead a long history with Flash. Thus creating a custom, dynamic and complex GUI is piece of cake to write for me in AS3 whereas trying to fight around with dotNet is a nightmare.

Also prototyping GUI ideas with flash is way faster as I have already the tools, classes and editors to try out stuff on the fly. And I guess in the end all what matters is that it works anyway

On the other hand I was not able yet to send back data from maxScript to JS. I also read something about a swf dotNet control but its way over my head translating those sources to maxscript + dotNet and in general there is a big lack of resources for this. So I am happy it worked with this hacky workaround.

Page 1 / 2