Jump to content
Search Community

Thorjelly

Members
  • Posts

    11
  • Joined

  • Last visited

Thorjelly's Achievements

0

Reputation

  1. Hey, Thanks for the reply. My ModuleLoader code is just this: package test { import com.greensock.loading.SWFLoader; import flash.system.ApplicationDomain; import flash.system.LoaderContext; public class ModuleLoader extends SWFLoader { private var _applicationDomain:ApplicationDomain; public function ModuleLoader(moduleUrl:String) { _applicationDomain = new ApplicationDomain(null); super(moduleUrl, { context: new LoaderContext(false, _applicationDomain) } ); } public function get applicationDomain():ApplicationDomain { return _applicationDomain; } } } That is, it just extends SWFLoader for a very easy to access applicationDomain property, so far. Anyway I tried to reproduce the problem in as little code as possible. I was not able to reproduce it however. Oddly, the problem is that I cannot reproduce it ever being fast to begin with -- in my test .fla it is slow no matter if it disposes or not. I'll try to see if I can reproduce it exactly and get back to you. Thanks
  2. Hey everyone, I have modules which are loaded in using the SWFLoader, and then faded onto the stage using TweenLite. This was working great. However, I am finding that whenever I dispose of the contents of the SWFLoader, it causes the tween to lag horribly, reducing very smooth fading to 3-5 fps. It works perfectly if I do not call dispose on the object. I am calling dispose before the tween is initialized. I would assume that if Dispose takes a while to complete, it should just cause the program to delay until it is done and then add the module and tween it. But this is not what is happening. I tried, instead of adding the displays of the modules right after the dispose command, adding an LoaderEvent.UNLOAD listener, and updating the displays after that gets fired. However, LoaderEvent.UNLOAD does not seem to fire at all, even using the command loader.empty(true, true) on a LoaderMax object which contains all the loaders for the modules that need to be loaded in at once. It should be noted, all the graphics are loading fine so it shouldn't be a problem with the content being flushed... in fact, even calling loader.dispose(false) in the individual SWFLoaders causes it to lag like this. Here is some code: _loadController = new LoaderMax( { onProgress: onLoadControllerProgress, onComplete: onLoadControllerComplete, maxConnections: 4 } ); // this actually starts the loading process; moduleDisplay dispatches // LoaderEvent.INIT (for lack of a better event name) after the loader // has been created, but the loader is not yet started. private function onModuleLoadInit(event:LoaderEvent):void { _loadController.append(event.target as ModuleLoader); _loadController.load(); } // If the download would take more than 2 seconds, show the loading // animation private function onLoadControllerProgress(event:LoaderEvent):void { var secondsLeft:Number = ((event.target.bytesTotal - event.target.bytesLoaded) / 1024) / WILDLoader.BANDWIDTH; if (secondsLeft > 2 && this.enabled) showPreloader(); } // when ALL loading is complete, clean up loader and update display private function onLoadControllerComplete(event:LoaderEvent):void { _loadController.empty(true, true); hidePreloader(); updateDisplays(); } Also, if I update the displays this way, it doesn't work at all because LoaderEvent.UNLOAD apparently fails to fire (the event listener is actually added in the constructor): _loadController = new LoaderMax( { onProgress: onLoadControllerProgress, onComplete: onLoadControllerComplete, onUnload: onLoadControllerUnload, maxConnections: 4 } ); // this actually starts the loading process; moduleDisplay dispatches // LoaderEvent.INIT (for lack of a better event name) after the loader // has been created, but the loader is not yet started. private function onModuleLoadInit(event:LoaderEvent):void { _loadController.append(event.target as ModuleLoader); _loadController.load(); } // If the download would take more than 2 seconds, show the loading // animation private function onLoadControllerProgress(event:LoaderEvent):void { var secondsLeft:Number = ((event.target.bytesTotal - event.target.bytesLoaded) / 1024) / WILDLoader.BANDWIDTH; if (secondsLeft > 2 && this.enabled) showPreloader(); } // when ALL loading is complete, clean up loader and update display private function onLoadControllerComplete(event:LoaderEvent):void { _loadController.empty(true, true); } // when the loader controller is unloaded, update displays and remove // preloader private function onLoadControllerUnload(event:LoaderEvent):void { hidePreloader(); updateDisplays(); } Does anyone know what could cause this sort of problem? Thanks
  3. Incidentally, and this is just an idea, but it might be useful for GreenSock to add a plugin for caching its own bitmap data into a tweened object, in a similar way that cacheAsBitmapForced above does. Because this really is a lot faster for complex objects than any of the other proposed solutions. Thanks for your support, though.
  4. Nah, my objects are not huge, they are just extremely detailed, with a lot of vector information. I will have to reduce the amount of vector information that is in the display objects or rethink the transitions to something that would be faster than a crossfade. Probably both. Thanks, though.
  5. Hey Carl, The smoothest way seems to be using cacheAsBitmapForced (as written above). This is extremely smooth, the only problem is the initial lag (which I still do not understand because it should be a process that runs before, and not concurrently with, the tween). Another solution I tried which is perhaps a bit less hackish than applying a color filter is to apply a mask on the display object, set cacheAsBitmap on the mask and the display object to true, and tween the alpha of the mask instead of the display object. I think this might have been a bit faster than applying the filter on the display object... but it was probably about the same speed. I suppose setting a filter is easier, though. Thanks anyway, Erik
  6. Hey carl, Thanks for the reply. I actually tried something like that, putting a glow filter onto the movie clip, but it didn't work. Oddly a BlurFilter and ColorMatrixFilter do. However, for the large, complex display objects, it has a very low frame rate, even with BlendMode.LAYER applied (in fact, the BlendMode doesn't appear to make any difference). Here is my code: target.cacheAsBitmap = true; target.blendMode = BlendMode.LAYER; target.filters = [new ColorMatrixFilter(null)]; target.alpha = 0; var tween:TweenLite = TweenLite.to(target, _fadeDuration, { alpha: 1, ease: Sine.easeInOut, onComplete: onAnimationComplete, onCompleteParams: [target] } ); private function onAnimationComplete(target:MovieClip):void { target.cacheAsBitmap = false; target.blendMode = BlendMode.NORMAL; target.filters = []; } Yes, but I do not make the tween until after the bitmap has been drawn, so it does not make any sense why it would lag, because no processor intensive action should happen while the tween is actually going. It should be happening before. I also tried to start the tween before cacheAsBitmapForced was set to true, and wrote tween.pause() and tween.resume() between setting cacheAsBitmapForced to true, and it still lagged.
  7. Okay well, I suppose this is a common issue, but amazingly I cannot find much in the way of information about it on these forums or anywhere else. But basically, when you change the alpha of a display object, it seems like essentially it changes the alpha of all its children, so that, for example, you can see through a child which was previously opaque into another child below when you set the alpha of the container to 0.5 or something. This not only isn't what I want, because it looks ugly, but rendering each child every frame with a new alpha is very slow while tweening! Unfortunately cacheAsBitmap doesn't work because it rerenders every time alpha changes, annoyingly. My solution was to extend a movieclip and write this into it, to be used whenever I tween alpha on a display object: public function get cacheAsBitmapForced():Boolean { return _cacheAsBitmapForced; } public function set cacheAsBitmapForced(value:Boolean):void { if (value != _cacheAsBitmapForced) { _cacheAsBitmapForced = value; var i:int; if (_cacheAsBitmapForced) { var bounds:Rectangle = this.getBounds(this); if (bounds.width > 0 && bounds.width < 2880 && bounds.height > 0 && bounds.height < 2880) { var matrix:Matrix = new Matrix(1, 0, 0, 1, -bounds.x, -bounds.y); var bitmapData:BitmapData = new BitmapData(bounds.width + 0.5, bounds.height + 0.5, true, 0); bitmapData.draw(this, matrix); _cachedBitmap = new Bitmap(bitmapData); _cachedBitmap.x = bounds.x; _cachedBitmap.y = bounds.y; for (i = 0; i < this.numChildren; i++) this.getChildAt(i).visible = false; super.addChild(_cachedBitmap); } else trace('Bitmap cannot be created for ' + this + '; size out of bounds.'); } else { if (_cachedBitmap && this.contains(_cachedBitmap)) this.removeChild(_cachedBitmap); _cachedBitmap = null; for (i = 0; i < this.numChildren; i++) this.getChildAt(i).visible = true; } } } And, okay, this works. But it is slow. I am working with large, detailed display objects with many children and sometimes this can take up to 150ms. And this isn't even the real crux of the problem. The real problem seems to be, for some reason, if I set cacheAsBitmapForced and then apply a tween, there is a lag in the tween so that the first 150ms that it is rendering the bitmap, nothing updates, and then suddenly it starts updating right in the middle of the tween, so my transitions are not smooth. This happens even if I apply the property and presumably it renders the bitmap and adds it to the stage -before- the tween is even applied. Why would it do this? Why wouldn't the tween start after the bitmap render is complete? Here is my code creating calling the tween, basically: target.cacheAsBitmapForced = true; target.alpha = 0; var tween:TweenLite = TweenLite.to(target, _fadeDuration, { alpha: 1, ease: Sine.easeInOut, onComplete: onAnimationComplete, onCompleteParams: target, } ); private function onAnimationComplete(target:WILDMovieClip):void { target.cacheAsBitmapForced = false; } So I suppose my questions are 1) is there a better way to deal with the problem of children inappropriately changing alpha and 2) why would the bitmap rendering cause a lag in the tween since supposedly it would be done before the tween is even created? I am sorry if this has been discussed before, I am sure it has been but I did a search and didn't find anything, really.
  8. Oh wow, awesome, it works now without all that onUpdate business That's pretty cool. Thanks!
  9. Yeah, that's right. I didn't look over it too carefully. Anyway, I am glad it works for you! And just for the record, just cus I could see how it could be confusing, for olly's example OverwriteManager would not need to be set to NONE, cus it isn't dealing with multiple tweens. That was just necessary for my problem In case anyone else stumbles through this.
  10. Okay well I came up with this solution: var tween:TweenLite = TweenLite.to(event.animationTarget, 0.5, { ease: Sine.easeInOut, onUpdate: onShadeUpdate }; tween.vars.onUpdateParams = [event.animationTarget, tween, start, end]; private function onShadeUpdate(target:WILDMovieClip, tween:TweenLite, start:Number, end:Number):void { var multiplier:Number = start * ((tween.duration - tween.currentTime) / tween.duration) + end * (tween.currentTime / tween.duration); target.transform.colorTransform = new ColorTransform(multiplier, multiplier, multiplier, target.alpha); } This only works with OverwriteManager set to NONE, though. Previously it did not work no matter what OverwriteManager was set to. The alpha tween would simply not finish ever, and it got stuck in a bizarre state. Anyway, you could do something similar, ollywood. Something like this: var tween:TweenLite = TweenMax.to(testIMG, 7, {onUpdate: onShadeUpdate}); tween.vars.onUpdateParams = [ testIMG, tween ]; private function onShadeUpdate(target:DisplayObject, tween:TweenLite):void { var redOffset:int = (tween.currentTime / 7) * 255; var greenOffset:int = Math.min(redOffset * (7 / 5), 255); var blueOffset:int = Math.min(blueOffset * (7 / 3), 255); target.transform.colorTransform = new ColorTransform(1, 1, 1, 1, redOffset, greenOffset, blueOffset); } might work?
  11. I have a similar problem. I was going to post my own topic about it but I'll post it here first. Basically, I cannot tween alpha and the ColorTransform of an object at the same time. Yes, I know I could use ColorTransform.alphaMultiplier if I am tweening the object from the same place, but these are two separate tweens initiated at two separate places that could be applied on the same object at the same time. This is a similar problem as described here: viewtopic.php?f=1&t=1777&p=6519&hilit=colortransform+alpha#p6519 However, I do not have the luxury of knowing that the alpha tween will be on the same object as a transform tween, so I can not arbitrarily add alphaMultiplier: 0 to each one of my transform tweens! Like described in that situation, my object just completely disappears (doesn't fade out, just vanishes altogether) and no alpha is tweened, even if I am trying to tween in to an alpha value of 1. Basically what seems to be happening is that ColorTransform bluntly overwrites any other color related transform, including the normal alpha property. This is sort of a problem with Flash -- you'd think that if you put an alpha value of 0.5 on a movieclip and then give it a color transform with an alphaMultiplier of 0.5 the total alpha would be 0.25, but no, Flash overwrites it. The solution I have found using Flash's native tween framework is essentially this: var tween:Tween = new Tween(mc, "", Regular.easeInOut, 1, 0.5, 0.5, true); tween.addEventListener(TweenEvent.MOTION_CHANGE, onShadeUpdate, false, 0, true); private function onShadeUpdate(event:TweenEvent):void { var tween:Tween = event.target as Tween; var target:WILDMovieClip = tween.obj as WILDMovieClip; target.transform.colorTransform = new ColorTransform(tween.position, tween.position, tween.position, target.alpha); } So basically, you create a miscellaneous value, and use that to create a new ColorTransform object using the tween.position property with whatever value you actually want to change, and set the alpha to be target.alpha, rather than 1 or anything like that. However I am not sure how to tween a 'miscellaneous value' in TweenLite or if that is even possible. What the ColorTransformPlugin SHOULD do is each time it updated the object's ColorTransform, it creates a ColorTransform that uses the old ColorTransform's values except for what values it is tweening... but this is apparently not what it actually does do. It apparently assumes that any value that you are not tweening is 1! That is all I can figure. If this is true, it seems like a bug in the ColorTransformPlugin and it should be fixed. But while it is like this, does anyone have a reasonable solution for this problem using TweenLite? Or am I wrong, and there is a perfectly rational explanation for this behavior, and an easy, intuitive solution?
×
×
  • Create New...