<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest posts for the topic "How to properly dispose of bitmap from MovieClipMaterial"]]></title>
		<link>http://forum.alternativaplatform.com/posts/list/40.page</link>
		<description><![CDATA[Latest messages posted in the topic "How to properly dispose of bitmap from MovieClipMaterial"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>How to properly dispose of bitmap from MovieClipMaterial</title>
				<description><![CDATA[ Hi!<br /> <br /> I've got problems with MovieClipMaterial<br /> <br /> When I change the material the bitmap from MovieClipMaterial remains in alt3d engine and is still used.<br /> <br /> First i change the material to new one and then I try:<br /> mcMaterial.texture.bitmapData.dispose();<br /> <br /> Bu then I get errors every frame: (even when there is another material assigned to the object)<br /> <br /> ArgumentError: Error #2015: Invalid BitmapData.<br /> 	at flash.display::BitmapData/fillRect()<br /> 	at alternativa.engine3d.materials::MovieClipMaterial/redraw()[G:\works\Alternativa3D\src\alternativa\engine3d\materials\MovieClipMaterial.as:111]<br /> <br /> thx<br /> T76<br /> ]]></description>
				<guid isPermaLink="true">http://forum.alternativaplatform.com/posts/preList/2979/50913.page</guid>
				<link>http://forum.alternativaplatform.com/posts/preList/2979/50913.page</link>
				<pubDate><![CDATA[Thu, 2 Sep 2010 14:35:58]]> GMT</pubDate>
				<author><![CDATA[ taurus76]]></author>
			</item>
			<item>
				<title>Re:How to properly dispose of bitmap from MovieClipMaterial</title>
				<description><![CDATA[ There's a bug in MovieClipMaterial. It's unlikely that there will be fix updates for 5.x version, so you can use this code for the material class to make your own.<br /> [code]package alternativa.engine3d.materials {<br /> <br /> 	import alternativa.engine3d.alternativa3d;<br /> 	import alternativa.engine3d.core.Surface;<br /> 	import alternativa.engine3d.events.MouseEvent3D;<br /> 	import alternativa.types.Texture;<br /> 	<br /> 	import flash.display.BitmapData;<br /> 	import flash.display.BlendMode;<br /> 	import flash.display.MovieClip;<br /> 	import flash.events.Event;<br /> 	import flash.geom.Matrix;<br /> 	import flash.geom.Rectangle;<br /> 	<br /> 	use namespace alternativa3d;<br /> <br /> 	public class MovieClipMaterial extends TextureMaterial {<br /> 		<br /> 		public var fillColor:uint;<br /> <br /> 		private var _movieClip:MovieClip;<br /> 		private var texWidth:uint;<br /> 		private var texHeight:uint;<br /> 		private var _fillRect:Rectangle;<br /> 		private var _clipRect:Rectangle;<br /> 		private var _matrix:Matrix;<br /> 		private var _refreshRate:int;<br /> 		private var _refreshCounter:int;<br /> <br /> 		public function MovieClipMaterial(movieClip:MovieClip, textureWidth:uint, textureHeight:uint, clipRect:Rectangle = null, matrix:Matrix = null, smooth:Boolean = false, precision:Number = 10, fillColor:uint = 0, refreshRate:int = 1) {<br /> 			texWidth = textureWidth;<br /> 			texHeight = textureHeight;<br /> 			_fillRect = new Rectangle(0, 0, texWidth, texHeight);<br /> 			if (clipRect != null) {<br /> 				_clipRect = clipRect.clone();<br /> 			}<br /> 			if (matrix != null) {<br /> 				_matrix = matrix.clone();<br /> 			}<br /> 			_texture = new Texture(new BitmapData(texWidth, texHeight));<br /> 			this.refreshRate = refreshRate;<br /> 			this.movieClip = movieClip;<br /> 			this.fillColor = fillColor;<br /> 			<br /> 			super(_texture, 1, false, smooth, BlendMode.NORMAL, -1, 0, precision);<br /> 		}<br /> <br /> 		public function get movieClip():MovieClip {<br /> 			return _movieClip;<br /> 		}<br /> 		<br /> 		public function set movieClip(value:MovieClip):void {<br /> 			if (value != _movieClip) {<br /> 				if (_movieClip != null) {<br /> 					// FIX begin<br /> 					if (_movieClip.parent != null)<br /> 						_movieClip.parent.removeChild(_movieClip);<br /> 					// FIX end<br /> 					_movieClip.removeEventListener(Event.ENTER_FRAME, redraw);<br /> 				}<br /> 				_movieClip = value;<br /> 				if (_movieClip != null) {<br /> 					_movieClip.addEventListener(Event.ENTER_FRAME, redraw);<br /> 				} else {<br /> 					_texture.bitmapData.fillRect(_fillRect, fillColor);<br /> 				}<br /> 			}<br /> 		}<br /> 		<br /> 		private function redraw(e:Event):void {<br /> 			if (_movieClip != null) {<br /> 				_refreshCounter++;<br /> 				if (_refreshCounter == _refreshRate) {<br /> 					_refreshCounter = 0;<br /> 					_texture.bitmapData.fillRect(_fillRect, fillColor);<br /> 					_texture.bitmapData.draw(_movieClip, _matrix, null, BlendMode.NORMAL, _clipRect, _smooth);<br /> 				}<br /> 			}<br /> 		}<br /> 		<br /> 		override alternativa3d function addToSurface(surface:Surface):void {<br /> 			super.addToSurface(surface);<br /> 			surface.addEventListener(MouseEvent3D.MOUSE_MOVE, onSurfaceMouseMove);<br /> 			surface.addEventListener(MouseEvent3D.MOUSE_OVER, onSurfaceMouseOverOut);<br /> 			surface.addEventListener(MouseEvent3D.MOUSE_OUT, onSurfaceMouseOverOut);<br /> 		}<br /> <br /> 		override alternativa3d function removeFromSurface(surface:Surface):void {<br /> 			super.removeFromSurface(surface);<br /> 			surface.removeEventListener(MouseEvent3D.MOUSE_MOVE, onSurfaceMouseMove);<br /> 			surface.removeEventListener(MouseEvent3D.MOUSE_OVER, onSurfaceMouseOverOut);<br /> 			surface.removeEventListener(MouseEvent3D.MOUSE_OUT, onSurfaceMouseOverOut);<br /> 		}<br /> 		<br /> 		private function onSurfaceMouseMove(e:MouseEvent3D):void {<br /> 			if (_movieClip != null) {<br /> 				_movieClip.x = e.view.mouseX - texWidth*e.u;<br /> 				_movieClip.y = e.view.mouseY - texHeight*(1 - e.v);<br /> 			}<br /> 		}<br /> 		<br /> 		private function onSurfaceMouseOverOut(e:MouseEvent3D):void {<br /> 			if (_movieClip != null) {<br /> 				if (e.type == MouseEvent3D.MOUSE_OVER) {<br /> 					e.view.addChild(_movieClip);<br /> 					_movieClip.alpha = 0;<br /> 				} else {<br /> 					if (_movieClip.parent == e.view) {<br /> 						e.view.removeChild(_movieClip);<br /> 					}<br /> 				}<br /> 			}<br /> 		}<br /> 		<br /> 		override public function set texture(value:Texture):void {<br /> 		}<br /> 		<br /> 		public function get refreshRate():int {<br /> 			return _refreshRate;<br /> 		}<br /> <br /> 		public function set refreshRate(value:int):void {<br /> 			_refreshRate = value &gt; 0 ? value : 1;<br /> 		}<br /> 		<br /> 		public function get clipRect():Rectangle {<br /> 			return _clipRect == null ? null : _clipRect.clone();<br /> 		}<br /> 		<br /> 		public function set clipRect(value:Rectangle):void {<br /> 			_clipRect = value;<br /> 		}<br /> 		<br /> 		public function get matrix():Matrix {<br /> 			return _matrix == null ? null : _matrix.clone();<br /> 		}<br /> 		<br /> 		public function set matrix(value:Matrix):void {<br /> 			_matrix = value;<br /> 		}<br /> 		<br /> 		override public function clone():Material {<br /> 			return new MovieClipMaterial(_movieClip, texWidth, texHeight, _clipRect, _matrix, _smooth, _precision, fillColor, _refreshRate);<br /> 		}<br /> <br /> 	}<br /> }[/code]]]></description>
				<guid isPermaLink="true">http://forum.alternativaplatform.com/posts/preList/2979/50943.page</guid>
				<link>http://forum.alternativaplatform.com/posts/preList/2979/50943.page</link>
				<pubDate><![CDATA[Fri, 10 Sep 2010 09:57:28]]> GMT</pubDate>
				<author><![CDATA[ mike]]></author>
			</item>
			<item>
				<title>Re:How to properly dispose of bitmap from MovieClipMaterial</title>
				<description><![CDATA[ how about opensourcing the rest of it? could make some noise on teh interwebs <img src="http://forum.alternativaplatform.com//images/smilies/3b63d1616c5dfcf29f8a7a031aaa7cad.gif" />]]></description>
				<guid isPermaLink="true">http://forum.alternativaplatform.com/posts/preList/2979/50944.page</guid>
				<link>http://forum.alternativaplatform.com/posts/preList/2979/50944.page</link>
				<pubDate><![CDATA[Fri, 10 Sep 2010 13:00:36]]> GMT</pubDate>
				<author><![CDATA[ makc]]></author>
			</item>
	</channel>
</rss>
