PDA

View Full Version : Resize Embed Object - AS2 Test


tsj4
07-15-2009, 11:44 PM
Trying to figure out how to resize the embed object in a html page without a reload of the swf on completion. I have achieved resizing the div and the flash object scales appropriately while also outputing the Stage.width & Stage.height corrcetly but once completed it reloads the swf.

I have attached the files


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>

<script>
$(document).ready(function(){
// Using multiple unit types within one animation.
$("#go").click(function(){
$("#block").animate({
width: "960",
height: "540"
}, 1500 );
});

});
</script>
<style>
div {
background-color:#ff0000;
width:352px;
height:540px;
border:1px solid green;
}
</style>
</head>
<body>
<button id="go">» Run</button>
<div id="block">
<object width="100%" height="100%"><param name="movie" value="MainStage_f8.swf"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="MainStage_f8.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="100%" height="100%"></embed></object>
</div>
</body>
</html>



class com.freestream.view.MainStage extends MovieClip {
var stageOnResizeListener:Object = new Object();

function MainStage() {
Stage.scaleMode = "noScale";
Stage.align = "TL";
stageOnResizeListener.onResize = stageOnResize;
Stage.addListener(stageOnResizeListener);
}

private function stageOnResize () {
_root.debug_txt.text += "Stage.width : "+Stage.width+", Stage.height : "+Stage.height+"\n"
}
}



Also the use of jQuery is not needed nor is the transition. I just need to be able to switch between these 352*540 & 960*540

tsj4
07-16-2009, 12:02 AM
This seems to only happen in FF / Mac. Just found bug report http://dev.jquery.com/ticket/4628

tsj4
07-16-2009, 02:02 AM
Here is the updated JS to achieve this in browsers other then FF / Mac.

pretty awesome since I have never wrote js beyond embedding a flash object.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<!--
To test make sure you running the files from a active web server which can be remote or local
-->

<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>

<script>
$(document).ready(function(){
// To use multiple unit types within one animation separate properties with a comma.
$("#go").click(function(){

e = document.getElementById('block').clientWidth;

k = 0;

if (e == 352) {
k = "960";
} else {
k = "352";
}

$("#block").animate({ width: k }, 0 );
});
});
</script>

<style>
div {
background-color:#ff0000;
width:352px;
height:540px;
border:1px solid green;
}
</style>
</head>

<body>
<button id="go">Toggle Size</button>

<div id="block">

<object width="100%" height="100%">
<param name="movie" value="MainStage_f8.swf"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="MainStage_f8.swf" type="application/x-shockwave-flash" allowscriptaccess="always" width="100%" height="100%"></embed>
</object>

</div>
</body>
</html>