Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-07-2009, 09:10 PM   #1
Thundordan
Registered Nurse
 
Join Date: Sep 2009
Posts: 5
Unhappy Filter interrupts mask tween



Hello,

I've made a class which creates an array of tweened disks which enlarge. I've sent this array to a stuff_mc.mask and it works.

Now, I've also applied a GlowFilter to stuff_mc which when I test the scene works great.

But if I run the output .swf file, the mask (the disks) stop enlarging at random positions one by one until the whole thing freezes (before it should end).

Any ideas on why does the filter break the mask's tween and why this doesn't also happen when I test movie?
Thundordan is offline   Reply With Quote
Old 11-07-2009, 09:29 PM   #2
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,908
Send a message via Skype™ to henke37
Default

Random stoping tweens? I think that the filters was not related at all to the real issue.

You are letting the tween object get garbage collected! This happens randomly and will kill the listeners that the tween object is using. The fix is simple, keep track of the tween object until the tween is over.
henke37 is offline   Reply With Quote
Old 11-07-2009, 11:08 PM   #3
Thundordan
Registered Nurse
 
Join Date: Sep 2009
Posts: 5
Question

I can't figure out what I'm doing wrong.. I think the code is pretty simple. Don't even need a class for it at this point.

here's the whole mask class:

Code:
package {
	import flash.display.DisplayObject; import flash.display.Sprite; import flash.display.MovieClip; 	import fl.transitions.Tween; import fl.transitions.easing.*;

    public class Disk extends MovieClip {
      
    private var diskWidth:Number = 85;
    private var diskHeight:Number = 85;
		
    private var disks:Number = 5;
    public var container:MovieClip = new MovieClip();
        
public function Disk() 
{
			
	for (var j=0; j < disks; j++) 
	{ 				
		var maskDisk:MaskDisk = new MaskDisk(); //MaskDisk is a movie clip symbol of a disk which isn't on stage
		var r:uint = 10;
		var r2:int = -10 + Math.random() * 20; //*(max-min)
		
		maskDisk.scaleY = maskDisk.scaleX = 0;
 
 		//Position the mask disks
		maskDisk.x = j * diskWidth  + 463 + r2;
		maskDisk.y = 573 + r2;
 
		var scaleTweenA:Tween = new Tween(maskDisk,"scaleX",Regular.easeIn,0,1.5,r,true);
		var scaleTweenB:Tween = new Tween(maskDisk,"scaleY",Regular.easeIn,0,1.5,r,true);
				
		container.addChild(maskDisk);
}}}}
here's where I use the class:
Code:
var myDisk:Disk = new Disk();
this.addChild(buttons_mc.mask = myDisk.container);
Again, if I also add the glow filter to buttons_mc, the swf freezes pretty much at the same point every time. (unless i say class extends Sprite in which case it freezes at a different point) :P

Last edited by Thundordan; 11-08-2009 at 10:24 AM.
Thundordan is offline   Reply With Quote
Old 11-08-2009, 12:26 PM   #4
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,908
Send a message via Skype™ to henke37
Default

Your error is here:
ActionScript Code:
var scaleTweenA:Tween = new Tween
You are using a local variable to hold the reference to the Tween instance. As soon the function returns, the object is eligable for garbage collection. The solution is to not use local variables for tweens, ever.
henke37 is offline   Reply With Quote
Old 11-08-2009, 06:22 PM   #5
Thundordan
Registered Nurse
 
Join Date: Sep 2009
Posts: 5
Default

Quote:
Originally Posted by henke37 View Post
Your error is here:
ActionScript Code:
var scaleTweenA:Tween = new Tween
You are using a local variable to hold the reference to the Tween instance. As soon the function returns, the object is eligable for garbage collection. The solution is to not use local variables for tweens, ever.
Okay I see how this could be bad.. But how else can I write a tween? I've looked around and I haven't found any other way to write it other than that.

I'm not very experienced in AS3..
Thundordan is offline   Reply With Quote
Old 11-08-2009, 07:05 PM   #6
chups
Registered User
 
Join Date: Oct 2009
Posts: 35
Default

You will have to make those tween variables become members of the class, not local variables of your constructor. Currently they reside in constructor, and when constructor finishes it's work, (and thats right after you started those tweens and added children) those tween variables are gone, and tween stops.

Declare them outside:
ActionScript Code:
private var scaleTweenA:Tween; private var scaleTweenB:Tween;
and assign inside the Disk() constructor:
ActionScript Code:
scaleTweenA = new Tween(maskDisk,"scaleX",Regular.easeIn,0,1.5,r,true); scaleTweenB = new Tween(maskDisk,"scaleY",Regular.easeIn,0,1.5,r,true);
Or you can download and use some custom made Tween classes, that are much easier to use.
chups is offline   Reply With Quote
Old 11-08-2009, 08:06 PM   #7
Thundordan
Registered Nurse
 
Join Date: Sep 2009
Posts: 5
Default

I had tried using a private var but I see I wasn't writing it properly. Thanks but it still didn't fix the problem

If I add the following code to the container I am masking, the first 4 disks stop tweening at about half way and only the 5th finishes it's animation..

Code:
            var filter:BitmapFilter = getBitmapFilter();
            var myFilters:Array = new Array();
	    myFilters.push(filter);
			
container_which_im_also_masking.filters = myFilters;
        
        function getBitmapFilter():BitmapFilter 
	{
            var color:Number = 0x000000;
            var Alpha:Number = 1;
            var blurX:Number = 10;
            var blurY:Number = 10;
            var strength:Number = 30;
            var inner:Boolean = false;
	    var knockout:Boolean = false;
            var quality:Number = BitmapFilterQuality.HIGH;

            return new GlowFilter(color, Alpha, blurX, blurY, strength, quality, inner, knockout);
        }

Last edited by Thundordan; 11-08-2009 at 08:08 PM.
Thundordan is offline   Reply With Quote
Reply


Thread Tools
Display Modes 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. The time now is 02:57 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.