A diary about programming problems - to help me more easily learn from (and Google) past mistakes.
Showing posts with label resize stage. Show all posts
Showing posts with label resize stage. Show all posts
Thursday, 27 May 2010
stageHeight after resize cont.
OK, it does pick it up, but technically, the stageHeight hasn't changed until the function has completed, so asking a movieClip to do something based on the new stageHeight when it hasn't actually changed yet is kind of silly...
stage.stageHeight after JavaScript's resize
I am trying to use the resize in an animation now, and I wanted the copyright movie clip to reposition itself when the movie got bigger. I got it to keep track of how far away it was from the bottom of the screen, but it didn't move, so I think perhaps that flash doesn't realise when it's stageHeight changes, but I will check on that now...
Wednesday, 26 May 2010
Resize in IE
I don't know what the problem was, maybe it was something in the html code... I was using code I got from Flash 8 output.
Anyway...
This is the html (I had to alter the html to get past the blog editor), it works for both IE and FF:
It resizes the area for the swf, and it also outputs the width of the file on top of the swf - just so I can remember how to use the div tag later.
The actionscript is really quite simple:
btn.addEventListener(MouseEvent.CLICK,callIt);
function callIt(evnt:MouseEvent) {
bg.width += 20;
bg.height += 20;
ExternalInterface.call('resize',bg.width,bg.height);
}
And voila!
Anyway...
This is the html (I had to alter the html to get past the blog editor), it works for both IE and FF:
<body>
<script type="text/javascript">
function resize(wid,heig) {
var infoTag = document.getElementById("info");
var objectTag = document.getElementById("divtest");
var embedTag = document.getElementById("embedTag");
infoTag.innerHTML = wid;
objectTag.setAttribute("width",wid);
objectTag.setAttribute("height",heig);
embedTag.setAttribute("width",wid);
embedTag.setAttribute("height",heig);
}
</script>
<div id='info'></div>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="500" height="500" id="divtest" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="sameDomain" />
<param name="movie" value="divtest.swf" />
<param name="quality" value="high" />
<param name="scale" value="noscale" />
<param name="salign" value="lt" />
<param name="bgcolor" value="#ffffff" />
<embed id="embedTag" src="divtest.swf" loop="false" menu="false" quality="high" scale="noscale" bgcolor="#ffffff" width="500" height="500" name="divtest" align="middle" salign="lt" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />
</object>
</body>
It resizes the area for the swf, and it also outputs the width of the file on top of the swf - just so I can remember how to use the div tag later.
The actionscript is really quite simple:
btn.addEventListener(MouseEvent.CLICK,callIt);
function callIt(evnt:MouseEvent) {
bg.width += 20;
bg.height += 20;
ExternalInterface.call('resize',bg.width,bg.height);
}
And voila!
Resizing the Stage
This code was pretty hard to get hold of on the internet, actually I couldn't find it. Anyone who came close to answering kind of seemed to assume that you knew what a 'DIV' tag was for and how to use it. Well, I didn't, and I didn't, but now I kind of do!
The problem is this, I will be making a swf whose length will change, depending on what the user writes, and it will certainly be longer than the screen. I don't want to make a really long swf, that people can scroll down even though there is nothing there, on the off chance that someone might enter enough text for it to need to be that long, and what if they write even more!
Also, most of the things that were addressing this, were trying to resize the stage, so it could fit in the browser window, and again, not my problem. Anyway, the code that they gave out was really complex, and I don't like to use code unless I understand what it actually means...
So, first things first, the 'DIV' tag.
Apparently, you can put this tag around things, give it an id attribute, and then refer to it with JavaScript. But, you can do this with ordinary tags anyway, so why bother (unless you have more than one swf on the page).
It works like this:
and then in your javascript function:
var swfTag = document.getElementById('embedtag');
Then you can alter its attributes:
swfTag.setAttribute('height','600');
The stage of the swf will automatically update, it doesn't refresh the movie or anything.
Then I had a bit of a problem with how the swf would be displayed on the new stage. It wouldn't be aligned to the side. Now I checked, and the movie clip that was on 0, still thought it was on 0, so it wasn't moving. I fixed this by adding an attribute to the embed tag -salign="lt"-aligning it's side to the left. I wasn't using the code output by the CS3 flash publisher, because it spits out so much javascript, I can't make sense of it, or how to alter it.
I put a button in my flash movie that increased the size of one of the movie clips on screen, and then used ExternalInterface to nake sure that the stage size on the html side of things was big enough, and with the salign="lt" bit, it worked.
I haven't tried it with the ie tag yet, what are the chances that I will come across some unexpected problems...quite high, I'd say.
The problem is this, I will be making a swf whose length will change, depending on what the user writes, and it will certainly be longer than the screen. I don't want to make a really long swf, that people can scroll down even though there is nothing there, on the off chance that someone might enter enough text for it to need to be that long, and what if they write even more!
Also, most of the things that were addressing this, were trying to resize the stage, so it could fit in the browser window, and again, not my problem. Anyway, the code that they gave out was really complex, and I don't like to use code unless I understand what it actually means...
So, first things first, the 'DIV' tag.
Apparently, you can put this tag around things, give it an id attribute, and then refer to it with JavaScript. But, you can do this with ordinary tags anyway, so why bother (unless you have more than one swf on the page).
It works like this:
<embed id="embedtag" src=...
and then in your javascript function:
var swfTag = document.getElementById('embedtag');
Then you can alter its attributes:
swfTag.setAttribute('height','600');
The stage of the swf will automatically update, it doesn't refresh the movie or anything.
Then I had a bit of a problem with how the swf would be displayed on the new stage. It wouldn't be aligned to the side. Now I checked, and the movie clip that was on 0, still thought it was on 0, so it wasn't moving. I fixed this by adding an attribute to the embed tag -salign="lt"-aligning it's side to the left. I wasn't using the code output by the CS3 flash publisher, because it spits out so much javascript, I can't make sense of it, or how to alter it.
I put a button in my flash movie that increased the size of one of the movie clips on screen, and then used ExternalInterface to nake sure that the stage size on the html side of things was big enough, and with the salign="lt" bit, it worked.
I haven't tried it with the ie tag yet, what are the chances that I will come across some unexpected problems...quite high, I'd say.
Labels:
as3,
div,
ExternalInterface,
Javascript,
resize stage
Subscribe to:
Posts (Atom)