Go Back   CodingForums.com > :: Client side development > Flash & ActionScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-07-2005, 04:22 AM   PM User | #1
rmedek
Senior Coder

 
Join Date: Nov 2003
Location: Minneapolis, MN
Posts: 2,879
Thanks: 2
Thanked 65 Times in 56 Posts
rmedek is on a distinguished road
can html trigger flash events?

I guess that's the question. I thought it would be simple to find an answer, but I'm having trouble finding a concise one.

Essentially I'd like an "onclick" event on a link to trigger a flash animation, rather than having an entire flash menu. Ideas?
__________________
drums | web
rmedek is offline   Reply With Quote
Old 01-07-2005, 01:15 PM   PM User | #2
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
u could try something like this
Code:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
function flashani(){
	document.getElementById("flash").innerHTML="<embed src='yourflash.swf' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='xx' height='xx'></embed>";
}
</script>
</head>

<body>
<a href="javascript:void();" onclick="flashani()">start flash</a>
<span id="flash"></span>
</body>
</html>
just be careful not to add any " in between the innerHTML quotes or u'll get a script error, but what this code does is with the onclick even in the link it will embed the flash file dynamically into the page into the span that has an id of flash, and just change the xx's in the height and width to your liking
_Aerospace_Eng_ is offline   Reply With Quote
Old 01-07-2005, 10:17 PM   PM User | #3
rmedek
Senior Coder

 
Join Date: Nov 2003
Location: Minneapolis, MN
Posts: 2,879
Thanks: 2
Thanked 65 Times in 56 Posts
rmedek is on a distinguished road
Thanks, but I'm not sure I'd go that route...

a) <a href="javascript:void();"... > isn't very accessible.

b) the animation will actually already be embedded; what I'm trying to do is have a link, when clicked, trigger a sound or movement from the animation, without having to have the entire menu in Flash.

Hopefully that clears things up a bit... thanks for your help, though
__________________
drums | web
rmedek is offline   Reply With Quote
Old 01-08-2005, 12:23 AM   PM User | #4
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,911
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
You are going to have to use javascript to talk to the flash movie , you cant do it in HTML , in which case the answer to your question is no .

if you give your flash embed/object tag an id ..

etc ... id="my_movie">

then set a refererence point (poxy detection (courtesy of MM ))
Code:
<script>
  var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
    var mc = InternetExplorer ? window.my_movie : window.document.my_movie;
/*e.g.*/
	function gotoframe(frame){
		mc.GotoFrame(frame) ;
	}
</script>
then <a href="javascript:gotoframe(5);">blah</a>

should work , once you have the movie reference (mc) you can even call functions and methods declared in that movie (e.g. mc.do_something(variable) )
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

Last edited by firepages; 01-08-2005 at 12:27 AM..
firepages is offline   Reply With Quote
Old 01-08-2005, 12:50 AM   PM User | #5
mindlessLemming
Senior Coder

 
Join Date: Oct 2003
Location: Australia
Posts: 1,963
Thanks: 0
Thanked 0 Times in 0 Posts
mindlessLemming is an unknown quantity at this point
Hmmm...
I did a quick bit of research, and apparently this should work:
Code:
<script type="text/javascript">
<!--
//<object> with id="movie"
function PassFlash(){
    document.getElementById('movie').SetVariable("text", "hello");
}
// <a> with id="playSwf"
document.getElementById('playSwf').onclick = PassFlash;
//-->
</script>
The 'SetVariable' function is from the MM docs, I think it may be horribly out of date (and won't work with IE/mac)

Then you would create an empty, hidden dynamic text field with a var of 'text' (not an instance name of 'text') which would receive the variable. To detect the presence of the variable from Flash, I'd use an onEnterFrame routine that starts the clip and calls 'delete onEnterFrame;' once the var has been found. The downside of this is that the onEnterFrame routine will eat the users resources (only a tiny bit, but still...) until it is told to get lost.

An easier way would be to dynamically insert a flashvar into the object tag, unfortunately those variables are read by flash on load, so you would have to find a way of triggering the flashvar import again, which would probably mean refreshing the <object> tag... not ideal, not at all

I'm happy to nut this one out a bit more, I just don't have Flash at home so I can't test any of these theories

Edit: Forget my insane jibberish -- go with firepages' option!
__________________

I take no responsibility for the above nonsense.


Left Justified

Last edited by mindlessLemming; 01-08-2005 at 12:55 AM..
mindlessLemming is offline   Reply With Quote
Old 01-08-2005, 01:47 AM   PM User | #6
rmedek
Senior Coder

 
Join Date: Nov 2003
Location: Minneapolis, MN
Posts: 2,879
Thanks: 2
Thanked 65 Times in 56 Posts
rmedek is on a distinguished road
Cool, thanks for the help guys!

I'm assuming that I can assign the target of the link to "href" and call the function through "onclick"? Keep in mind I'm a Flash/Javascript idiot...

Either way, the movie reference function is just what I need...
__________________
drums | web
rmedek is offline   Reply With Quote
Old 01-08-2005, 04:03 AM   PM User | #7
mindlessLemming
Senior Coder

 
Join Date: Oct 2003
Location: Australia
Posts: 1,963
Thanks: 0
Thanked 0 Times in 0 Posts
mindlessLemming is an unknown quantity at this point
Quote:
Originally Posted by rmedek
I'm assuming that I can assign the target of the link to "href" and call the function through "onclick"?
Yep
And you'll also want to 'return false;' so the link isn't followed if js is working.
Actually, how are you handling the detection of flash + js? I'm thinking the JS should try and pull a variable or reference the Flash and if it can't (which means flash isn't supported) then it doesn't add the onclick to the link either. That way if the user has javascript but not flash, the link will still point to the html page in the href... does that sound feasible? Maybe I'm off track...
__________________

I take no responsibility for the above nonsense.


Left Justified
mindlessLemming is offline   Reply With Quote
Old 01-08-2005, 08:05 AM   PM User | #8
rmedek
Senior Coder

 
Join Date: Nov 2003
Location: Minneapolis, MN
Posts: 2,879
Thanks: 2
Thanked 65 Times in 56 Posts
rmedek is on a distinguished road
Quote:
Originally Posted by mindlessLemming
Actually, how are you handling the detection of flash + js? I'm thinking the JS should try and pull a variable or reference the Flash and if it can't (which means flash isn't supported) then it doesn't add the onclick to the link either. That way if the user has javascript but not flash, the link will still point to the html page in the href... does that sound feasible? Maybe I'm off track...
Oh man, there you go offering valuable, accessible advice that only makes me work harder

I was just planning to offer text link alternatives, but your method seems like something I should at least try. Again, I am a total js/flash newbie, so this might take awhile The Flash, btw, is only for a silly effect; there's a floating head that makes comments based on your navigation choices. (yes, this is a fun website I'm working on!)
__________________
drums | web

Last edited by rmedek; 01-15-2005 at 10:41 PM..
rmedek is offline   Reply With Quote
Old 01-15-2005, 10:10 PM   PM User | #9
Crake
Regular Coder

 
Crake's Avatar
 
Join Date: Dec 2004
Location: Loose, Maidstone, KENT
Posts: 577
Thanks: 0
Thanked 3 Times in 3 Posts
Crake is an unknown quantity at this point
i never knew

if it cud trigger flash events! learn soming new every day
Crake is offline   Reply With Quote
Old 01-15-2005, 10:41 PM   PM User | #10
rmedek
Senior Coder

 
Join Date: Nov 2003
Location: Minneapolis, MN
Posts: 2,879
Thanks: 2
Thanked 65 Times in 56 Posts
rmedek is on a distinguished road
omg yess u rnt kdding!
__________________
drums | web
rmedek is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:49 AM.


Advertisement
Log in to turn off these ads.