Pages: [1]
  Print  
Author Topic: Still trouble with Hijacking on Preloader  (Read 515 times)
lddd
Gaia User
**
Posts: 45



« on: July 29, 2010, 03:48:28 PM »

Hey again,

i can´t figure out my problems on hijacking to have a custom animation beforePreload.
I have a simple preloader (created on runtime over Preloader.as,PreloaderScaffold.as)

In my PreloaderScaffold where i have my code for all Preloader Graphics and the entire
Animation Process of the Preloader (scaling bar) i would like to add my custom animation
MovieClip before preloading

Now i added the following:

Code:
/*****************************************************************************************************
* Gaia Framework for Adobe Flash ©2007-2009
* Author: Steven Sacks
*
* blog: http://www.stevensacks.net/
* forum: http://www.gaiaflashframework.com/forum/
* wiki: http://www.gaiaflashframework.com/wiki/
*
* By using the Gaia Framework, you agree to keep the above contact information in the source code.
*
* Gaia Framework for Adobe Flash is released under the GPL License:
* http://www.opensource.org/licenses/gpl-2.0.php
*****************************************************************************************************/

package pages
{
import com.gaiaframework.templates.AbstractPreloader;
import com.gaiaframework.api.Gaia;
import com.gaiaframework.events.*;
import com.greensock.TweenMax;
import com.pcthomatos.utilities.SpriteRegPoint;
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.media.Sound;
import flash.media.SoundChannel;
import com.flinq.ScrollingLetter;

public class BarPreloader extends Sprite
{

public var bar:Sprite = new Sprite  ;
private var releaseGaia:Function = Gaia.api.beforePreload(onBeforePreload,true);

public function BarPreloader()
{
super();
alpha = 1;
bar.scaleX = 0;
visible = false;
mouseEnabled = mouseChildren = false;
addEventListener(Event.ADDED_TO_STAGE,onAddedToStage);
}

private function onBeforePreload(e:GaiaEvent):void
{
// Here i would like to add a instance of ScrollingLetter before the Preloader Starts
var _scroll:ScrollingLetter = new ScrollingLetter  ;
addChild(_scroll);
                       // This is just for timing, it should give my ScrollingLetter instance 3 seconds until the entire preloader comes in and everything resumes
TweenMax.delayedCall(3, releaseGaia);
}

private function onAddedToStage(event:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE,onAddedToStage);
stage.addEventListener(Event.RESIZE,onResize);
onResize();
}

public function transitionIn():void
{
TweenMax.to(this,.1,{autoAlpha:1});

//Create the entire Process Bar updating preloading process;
bar.graphics.beginFill(0x000000,1);
bar.graphics.drawRect(0,0,stage.stageWidth,3);
bar.graphics.endFill();
addChild(bar);
}

public function transitionOut():void
{
TweenMax.to(this,.1,{autoAlpha:0});
}

public function onProgress(event:AssetEvent):void
{
// if bytes, don't show if loaded = 0, if not bytes, don't show if perc = 0
// the reason is because all the files might already be loaded so no need to show preloader
visible = event.bytes ? event.loaded > 0:event.perc > 0;

// progress bar scale times percentage (0-1)
bar.scaleX = event.perc;


}
private function onResize(event:Event=null):void
{
x = Gaia.api.getWidth() - width / 2;
y = Gaia.api.getHeight() - height / 2;
}
}
}

So i think i do something wrong here:

Code:
private function onBeforePreload(e:GaiaEvent):void
{
// Here i would like to add a instance of ScrollingLetter before the Preloader Starts
var _scroll:ScrollingLetter = new ScrollingLetter  ;
addChild(_scroll);
                       // This is just for timing, it should give my ScrollingLetter instance 3 seconds until the entire preloader comes in and everything resumes
TweenMax.delayedCall(3, releaseGaia);
}

delayedCall is working, it waits to continues with the flow for 3 seconds. But my display list object is not visible to the stage
And i don´t get it why it´s not visible.    

This is actually the same problem i have with tweening any stuff here on TweenMax.to() and trying to releaseGaia
with the onComplete() method in my onBeforePreload function. And i wonder why i can have a
TweenMax.delayedCall(time, releaseGaia) but everything else like adding something, tweening it, fails.
Its only visible when everything resumes, but i want a hijacker to make it visible before it resumes Wink
« Last Edit: July 29, 2010, 03:58:53 PM by lddd » Logged

keep it simple stupid
steven
Gaia Author
Administrator
Gaia Evangelist
*****
Posts: 3871


gaiaframework
WWW
« Reply #1 on: August 02, 2010, 12:12:37 PM »

I keep seeing people make the mistake of setting a hijacker inside a variable declaration and I keep saying don't do it.

Do this:
Code:
private var releaseGaia:Function;

And move the beforePreload hijacker into the class constructor.
Logged

Steven Sacks | Gaia Author
Please support Gaia by donating to the project!  Smiley
lddd
Gaia User
**
Posts: 45



« Reply #2 on: August 02, 2010, 01:15:30 PM »

Thank you steven, got it working now and i am looking forward donating the project :-)
By the way some thing i messed up with was alpha=0 and visible = false in
the Preloaders Constructor. Thats why my objects were not visible
to the stage., lulz... ;-)
« Last Edit: August 02, 2010, 01:31:02 PM by lddd » Logged

keep it simple stupid
lddd
Gaia User
**
Posts: 45



« Reply #3 on: August 05, 2010, 04:30:42 AM »

Btw, if i have one hijacker in my constructor that fires "onBeforePreload" where should i add a second one "onAfterPreload".? I setted up a second one just after the first one in my constructor but it just gets ignored once releaseGaiaBefore from the first hijack function is called.

Code in my Constructor:

Code:
public function BarPreloader()
{
super();
alpha = 1;
bar.scaleX = 0;
visible = true;
mouseEnabled = mouseChildren = false;
addEventListener(Event.ADDED_TO_STAGE,onAddedToStage);

//Gaia Hijacker for "onBeforePreload"
releaseGaiaBefore = Gaia.api.beforePreload(onBeforePreload,true);
//Gaia Hijacker for "onAfterPreload"
releaseGaiaAfter = Gaia.api.afterPreload(onAfterPreload, true);

// Gaia onBeforePreload Function (Setting Preloader "Loading Website..." Message!
function onBeforePreload(e:GaiaEvent):void {
// Setting up "Loading... Text"
var _scrollBefore:ScrollingLetterBefore = new ScrollingLetterBefore;
addChild(_scrollBefore);
TweenMax.delayedCall(2, releaseGaiaBefore);
}

// Gaia onAfterPreload Function (Setting Preloader "Complete..." Message!
function onAfterPreload(e:GaiaEvent):void {
// Setting up "Loading... Text"
var _scrollAfter:ScrollingLetterAfter = new ScrollingLetterAfter;
addChild(_scrollAfter);
TweenMax.delayedCall(2, releaseGaiaAfter);
}

}



« Last Edit: August 05, 2010, 04:32:23 AM by lddd » Logged

keep it simple stupid
Pages: [1]
  Print  
 
Jump to:  

TinyPortal v1.0 beta 4 © Bloc