Embedding Flash in .app, Round Two
8 answers - 2302 bytes -

As mentioned before, I have need to embed a Flash file in an app
basically as an NSView subclass. Basically, I need to have on this
class something akin to:
- (BL) initWithURL:(NSURL) urlToSWF;
- (NSString *) getFlashVariable:(NSString *) var;
- (NSString *) setFlashVariable:(NSString *) var toValue:(NSString *)
val;
And a delegate which accepts fscommand calls from the Flash movie with:
- (void) doFSCommand:(NSString *)command withArgs:(NSString *)args;
I tried using NSMovieView, and wrote a subclass which did all this.
This embedded a number of Flash files quite nicely, including the basic
Macromedia samples. Unfortunately, it doesn't seem to work quite
right.
But with Quicktime 7 you cannot load Flash files containing alpha (and
ours do) or which are compressed (and ours are). And while some sample
files worked fine with setVariable and fscommand interaction using
MCActionFilter stuff and FlashMediaSetFlashVariable, not all -- and not
ours (with the alpha masking removed and compression off, of course) --
did.
It's not a Flash file problem, though: over on Windows XP, embedding
the Flash ActiveX control in a window and loading one of the files on
Windows works fine, both for playback and for interaction/communication
with the ActiveScript code in the Flash file.
Now, being a Mac devotee, I'm certain there has to be a way to do this
at least as cleanly. But NSMovieView clearly isn't going to cut it.
I've gone back to looking at using WebView and just calling the Flash
plugin, but it seems I'll have to do some serious black magic voodoo in
order to have a WebView-derived class that will handle what I want to
do cleanly. (Like rewriting temporary HTML files and loading them, and
doing some really scary dynamic Javascript voodoo to do the
set/get/fscommand stuff.)
So, again, I ask anyone have any better ideas for me? I'm right now
considering whether or not it would be possible to load the Flash
plugin directly as if I /were/ Webkit, and interact with it that way.
But at this point, I'll take anything: even just a better idea on how
do to this with WebKit so that it's not evil. :)
No.1 | | 2492 bytes |
| 
If you figure this out, let me know. I've always wanted a way to
embed a Flash into an app that didn't suck :)
Jan 3, 2006, at 1:31 PM, Rachel Blackman wrote:
As mentioned before, I have need to embed a Flash file in an app
basically as an NSView subclass. Basically, I need to have on this
class something akin to:
- (BL) initWithURL:(NSURL) urlToSWF;
- (NSString *) getFlashVariable:(NSString *) var;
- (NSString *) setFlashVariable:(NSString *) var toValue:
(NSString *) val;
And a delegate which accepts fscommand calls from the Flash movie
with:
- (void) doFSCommand:(NSString *)command withArgs:(NSString *)args;
I tried using NSMovieView, and wrote a subclass which did all
this. This embedded a number of Flash files quite nicely,
including the basic Macromedia samples. Unfortunately, it doesn't
seem to work quite right.
But with Quicktime 7 you cannot load Flash files containing alpha
(and ours do) or which are compressed (and ours are). And while
some sample files worked fine with setVariable and fscommand
interaction using MCActionFilter stuff and
FlashMediaSetFlashVariable, not all -- and not ours (with the alpha
masking removed and compression off, of course) -- did.
It's not a Flash file problem, though: over on Windows XP,
embedding the Flash ActiveX control in a window and loading one of
the files on Windows works fine, both for playback and for
interaction/communication with the ActiveScript code in the Flash
file.
Now, being a Mac devotee, I'm certain there has to be a way to do
this at least as cleanly. But NSMovieView clearly isn't going to
cut it. I've gone back to looking at using WebView and just
calling the Flash plugin, but it seems I'll have to do some serious
black magic voodoo in order to have a WebView-derived class that
will handle what I want to do cleanly. (Like rewriting temporary
HTML files and loading them, and doing some really scary dynamic
Javascript voodoo to do the set/get/fscommand stuff.)
So, again, I ask anyone have any better ideas for me? I'm right
now considering whether or not it would be possible to load the
Flash plugin directly as if I /were/ Webkit, and interact with it
that way. But at this point, I'll take anything: even just a
better idea on how do to this with WebKit so that it's not evil. :)
No.2 | | 594 bytes |
| 
So, again, I ask anyone have any better ideas for me? I'm right
now considering whether or not it would be possible to load the Flash
plugin directly as if I /were/ Webkit, and interact with it that way.
But at this point, I'll take anything: even just a better idea on how
do to this with WebKit so that it's not evil. :)
And, as a follow-up, does anyone know why the documentation claims that
the 'windowS' method on WebView, and the WebS
such a method returns, are 'in 10.3.9 and later' but 10.3.9 has no clue
what either is? ;)
No.3 | | 4540 bytes |
| 
Here's a trivial app that embeds the "Badger Badge Badger" flash movie.
(352k, slow server)
Source:
(2.4M, slow server)
It's simply a WebView, with this code in the application delegate:
-(void)awakeFromNib
{
NSString *path = [[NSBundle mainBundle]
pathForResource:@"badger" ofType:@"swf"];
NSData *flash = [NSData dataWithCFile:path];
[[wv mainFrame] loadData:flash
MIMEType:@"application/x-shockwave-flash"
textEncodingName:@"utf-8"
baseURL:nil];
}
Does the trick.
It does pop up a Flash warning about badger.swf wanting to phone home
to
Presumably your flash files won't do that.
-M
Jan 3, 2006, at 6:54 PM, John Stiles wrote:
If you figure this out, let me know. I've always wanted a way to
embed a Flash into an app that didn't suck :)
Jan 3, 2006, at 1:31 PM, Rachel Blackman wrote:
>
>As mentioned before, I have need to embed a Flash file in an app
>basically as an NSView subclass. Basically, I need to have on
>this class something akin to:
>>
>- (BL) initWithURL:(NSURL) urlToSWF;
>- (NSString *) getFlashVariable:(NSString *) var;
>- (NSString *) setFlashVariable:(NSString *) var toValue:
>(NSString *) val;
>>
>And a delegate which accepts fscommand calls from the Flash movie
>with:
>>
>- (void) doFSCommand:(NSString *)command withArgs:(NSString *)args;
>>
>I tried using NSMovieView, and wrote a subclass which did all
>this. This embedded a number of Flash files quite nicely,
>including the basic Macromedia samples. Unfortunately, it doesn't
>seem to work quite right.
>>
>But with Quicktime 7 you cannot load Flash files containing alpha
>(and ours do) or which are compressed (and ours are). And while
>some sample files worked fine with setVariable and fscommand
>interaction using MCActionFilter stuff and
>FlashMediaSetFlashVariable, not all -- and not ours (with the
>alpha masking removed and compression off, of course) -- did.
>>
>It's not a Flash file problem, though: over on Windows XP,
>embedding the Flash ActiveX control in a window and loading one of
>the files on Windows works fine, both for playback and for
>interaction/communication with the ActiveScript code in the Flash
>file.
>>
>Now, being a Mac devotee, I'm certain there has to be a way to do
>this at least as cleanly. But NSMovieView clearly isn't going to
>cut it. I've gone back to looking at using WebView and just
>calling the Flash plugin, but it seems I'll have to do some
>serious black magic voodoo in order to have a WebView-derived
>class that will handle what I want to do cleanly. (Like rewriting
>temporary HTML files and loading them, and doing some really scary
>dynamic Javascript voodoo to do the set/get/fscommand stuff.)
>>
>So, again, I ask anyone have any better ideas for me? I'm
>right now considering whether or not it would be possible to load
>the Flash plugin directly as if I /were/ Webkit, and interact with
>it that way. But at this point, I'll take anything: even just a
>better idea on how do to this with WebKit so that it's not evil. :)
>>
>--
>Rachel 'Sparks' Blackman -- sysadmin, developer, mad scientist
>"If it is not broken, give me five minutes to redesign it!"
>>
>
>Do not post admin requests to the list. They will be ignored.
>Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
>Help/Unsubscribe/Update your Subscription:
>%
>40blizzard.com
>>
>This email sent to jstiles (AT) blizzard (DOT) com
>
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
Help/Unsubscribe/Update your Subscription:
%40rothwell.us
This email sent to michael (AT) rothwell (DOT) us
No.4 | | 456 bytes |
| 
Here's a trivial app that embeds the "Badger Badge Badger" flash movie.
(352k, slow server)
The issue here is that the WebView (as set up in this) doesn't provide
for Flash interactivity. I.e., receiving fscommand calls from the
Flash file, nor sending setVariable messages to Flash.
Loading the Flash file is no issue it's getting at the
'swliveconnect' functionality that's giving me a headache. :)
No.5 | | 975 bytes |
| 
1/3/06, Rachel Blackman <seattlesparks (AT) mac (DOT) comwrote:
The issue here is that the WebView (as set up in this) doesn't provide
for Flash interactivity. I.e., receiving fscommand calls from the
Flash file, nor sending setVariable messages to Flash.
Loading the Flash file is no issue it's getting at the
'swliveconnect' functionality that's giving me a headache. :)
Can't you use XML-RPC or REST or similar? I've written Python apps
with embedded XML-RPC servers, to which the embedded swf could
communicate via localhost. This avoids many issues with the wrapper,
as long as networking still works.
J.
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
Help/Unsubscribe/Update your Subscription:
%40developershed.com
This email sent to bsdarchive (AT) developershed (DOT) com
No.6 | | 1346 bytes |
| 
I might have a partial solution for you:
I believe Flash will automatically set variables for you if you
attach them in a GET URL request.
So, if you had a URL like this: file://PATH_TMVIE.swf?myVar=x
When the flash movie is launched it should automatically set myVar to x
Now, the problem is that will only work when loading the movie, so if
you have to set variables in the middle of the movie, it will be harder.
As for receiving fscommands, I dont really know. With actionscript,
you can write cookies which you could intercept with webkit or write
to a temporary file and watch it for changes.
Hope that helps
Jan 3, 2006, at 6:03 PM, Rachel Blackman wrote:
The issue here is that the WebView (as set up in this) doesn't
provide for Flash interactivity. I.e., receiving fscommand calls
from the Flash file, nor sending setVariable messages to Flash.
Loading the Flash file is no issue it's getting at the
'swliveconnect' functionality that's giving me a headache. :)
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
Help/Unsubscribe/Update your Subscription:
%40developershed.com
This email sent to bsdarchive (AT) developershed (DOT) com
No.7 | | 686 bytes |
| 
Hi Rachel,
The problem with QT based Flash is that it only supports Flash 5.
Flash 5 was one of the least stable of the releases to date, and will
generally drive you nuts. If you end up going this route though,
there's a lot of sample code out there.
I too would really like to see the plug-in architecture for browsers
become a drop-in object for applications.
-Chilton
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
Help/Unsubscribe/Update your Subscription:
%40developershed.com
This email sent to bsdarchive (AT) developershed (DOT) com
No.8 | | 1904 bytes |
| 
The issue here is that the WebView (as set up in this) doesn't
provide for Flash interactivity. I.e., receiving fscommand calls
from the Flash file, nor sending setVariable messages to Flash.
Loading the Flash file is no issue it's getting at the
'swliveconnect' functionality that's giving me a headache. :)
, I finally made it work!
For those who are curious (since I got a lot of off-list 'if you
figure this out, let me know' mail), the solution isn't quite as
clean as I might've hoped. The Flash plugin's security model is such
that unless the Flash and page are loaded from the web (no file://)
and have a matching domain portion of the URL, it won't enable
liveconnect.
This is annoying.
But in the end, since our Flash files were coming from a specific
remote server anyway, I wrote a PHP wrapper which takes a parameter
of the swf file in our collection, and hands back a pre-generated
webpage. The Flash is embedded (with 100% width and 95% height) with
a specific name ('csflash'), and a Javascript function for
csflash_FSCommand is also included which simply calls
(command,args).
When the WebS becomes available, I add the view itself as
CSFlashEngine. The view has a registered delegate, which then will
receive 'fsCommand' handed back off from the view whenever the Flash
generates an event. Sending variables to the Flash file is easy
enough, just a matter of using the WebS to evaluate
'document.csflash.setVariable()' calls.
the plus side, I now have a nice embeddable view, where I just do
a single call to load a Flash file, and voila, I get back the
fscommand calls. the down side, it's not quite as generally
reusable as I hoped because of Flash's security model. Fooie.