target after load.complete

3 views
Skip to first unread message

Ludovic Roux

unread,
Dec 4, 2008, 6:30:21 AM12/4/08
to mas...@googlegroups.com
Hello everybody,
In first, sorry my english...

So, I am trying Masapi for a Full Flash website, with a lot of animations, sounds, etc...
I can load all the files and see them. 
But I can't control them. 

Exemple

Index.swf :

//get files
var file1:ILoadableFile = cml.getFileAt(0); // png
var file2:ILoadableFile = cml.getFileAt(1); // swf
var file3:ILoadableFile = cml.getFileAt(2); // swf with a button
var file4:ILoadableFile = cml.getFileAt(3); // swf
var file5:ILoadableFile = cml.getFileAt(4); // swf

//get files into a Loader
var ldr:Loader = file1.getData("flash.display.Loader"); 
var ldr2:Loader = file2.getData("flash.display.Loader"); 
var ldr3:Loader = file3.getData("flash.display.Loader"); 
var ldr4:Loader = file4.getData("flash.display.Loader"); 
var ldr5:Loader = file5.getData("flash.display.Loader"); 


addChild(ldr); //
addChild(ldr2); //
addChild(ldr3); //
addChild(ldr4); //
addChild(ldr5); //

Explication :

When I press my button into ldr3, I want to control ldr4 (visible = false).
I try to check the target with this code into ldr3 :

trace(root)
trace(root.parent)
trace(parent)
trace(root.parent.root);

I have :

[object MainTimeline]
[object Loader]
[object Loader]
null


I think my target is not correct (null)

Thank you for your help and thanks for MASAPI

Ludo




Cédric Tabin

unread,
Dec 4, 2008, 8:29:48 AM12/4/08
to mas...@googlegroups.com
Hello,

You must wait that the file are loaded... How do you create the files and when do you execute this code ?

Regards,
Cedric

lal...@free.fr

unread,
Dec 4, 2008, 11:07:28 AM12/4/08
to masapi
Hello, thanks to help me Cédric.
I think that all my files are loaded. I am going to explain my work. I
hope it is good ...

I have images and swf to load.
index.swf is loading the others.
Into chateau.swf, I have a button. this button can control other swf
loaded.

Details :

>> Into index.swf / Frame 1 :

stop();


import ch.capi.net.*;
import ch.capi.events.*;
import flash.events.*;
import fl.transitions.*;
import fl.transitions.easing.*;


// Init path
var cheminIMG:String = "img/";
var cheminSWF:String = "anim/";
var cheminTRANS:String = "trans";
var cheminBUR:String = "bur";
var cheminCOUL:String = "coul";



// loader
var cml:CompositeMassLoader = new CompositeMassLoader();
cml.addFile(cheminIMG + "nuage.png", LoadableFileType.SWF);
cml.addFile(cheminIMG + "nuages2.png", LoadableFileType.SWF);
cml.addFile("chateau.swf", LoadableFileType.SWF);
cml.addFile(cheminSWF + "animationBrume.swf", LoadableFileType.SWF);
cml.addFile(cheminIMG + "masqueNoir.png", LoadableFileType.SWF);
cml.addFile(cheminTRANS + "transitionFondu.swf",
LoadableFileType.SWF);
cml.addFile(cheminBUR + "bureau.swf", LoadableFileType.SWF);
cml.addFile(cheminCOUL + "couloir.swf", LoadableFileType.SWF);


// Listener
cml.massLoader.addEventListener(Event.OPEN, handleOpen);
cml.massLoader.addEventListener(ProgressEvent.PROGRESS,
handleProgress);
cml.massLoader.addEventListener(Event.COMPLETE, handleComplete);
cml.massLoader.addEventListener(MassLoadEvent.FILE_OPEN,
handleFileOpen);
cml.massLoader.addEventListener(MassLoadEvent.FILE_CLOSE,
handleFileClose);


cml.start();

// Functions
function handleOpen(evt:Event):void { trace("Start loading"); }

function handleProgress(evt:ProgressEvent):void
{
var percent:Number = Math.round(evt.bytesLoaded / evt.bytesTotal *
100);
loadingMC.testCharge.text = percent;
}


function handleComplete(evt:Event):void
{
trace ("Loading Finish");

// Animation
var startValue:Number = loadingMC.y;
var finishValue:Number = 800;
var duration:Number = 1;
var barreAlpha:Number = 1;
var lance:Tween = new Tween(loadingMC, "y", Back.easeIn, startValue,
finishValue, duration, true);
var lanceAlpha:Tween = new Tween(loadingMC, "alpha", Regular.easeIn,
barreAlpha, 0, duration, true);

// timing
var moteur:Timer = new Timer(1000,1);
moteur.addEventListener(TimerEvent.TIMER,avancer);
moteur.start();

}

function avancer(evt:TimerEvent) {
play();
}

function handleFileOpen(evt:MassLoadEvent):void { trace("ouverture du
fichier : "+evt.file); }
function handleFileClose(evt:MassLoadEvent):void { trace("fermeture du
fichier : "+evt.file+", status : "+evt.closeEvent); }

>> Into index.swf / Frame 2 :

stop();

import ch.capi.net.*;
import ch.capi.events.*;
import flash.events.*;
import flash.display.*;


var file1:ILoadableFile = cml.getFileAt(0);
var file2:ILoadableFile = cml.getFileAt(1);
var file3:ILoadableFile = cml.getFileAt(2);
var file4:ILoadableFile = cml.getFileAt(3);
var file5:ILoadableFile = cml.getFileAt(4);
var file6:ILoadableFile = cml.getFileAt(5);
var file7:ILoadableFile = cml.getFileAt(6);
var file8:ILoadableFile = cml.getFileAt(7);

var ldr:Loader = file1.getData("flash.display.Loader");
var ldr2:Loader = file2.getData("flash.display.Loader");
var ldr3:Loader = file3.getData("flash.display.Loader");
var ldr4:Loader = file4.getData("flash.display.Loader");
var ldr5:Loader = file5.getData("flash.display.Loader");
var ldr6:Loader = file6.getData("flash.display.Loader");
var ldr7:Loader = file7.getData("flash.display.Loader");
var ldr8:Loader = file8.getData("flash.display.Loader");


addChildAt(ldr,0);
addChildAt(ldr2,1);
addChildAt(ldr3,2);
addChildAt(ldr4,3);
addChildAt(ldr5,4);
addChildAt(ldr6,5);




// Animation
MovieClip(ldr6.content).play();

// Enabled : to access button into ldr3
ldr4.mouseEnabled=false;
ldr4.mouseChildren=false;
ldr5.mouseEnabled=false;
ldr5.mouseChildren=false;
ldr6.mouseEnabled=false;
ldr6.mouseChildren=false;

// Function
function etatTransition(evt:Event){
// change movie into ldr3
// control ldr4, ldr5, ldr6
}

>> Into chateau.swf / Frame1


trace("**");
trace("CHECK le chemin du chateau : ")
trace(root)
trace(root.parent)
trace(parent)
trace(root.parent.root);
trace("**");

var racine = root.parent.root

// function
function lance(evt:MouseEvent) {
this.buttonMode = true;
trace("Clic sur la porte");
MovieClip(racine).etatTransition();// target the function into
index.swf

}

function etatOver(evt:MouseEvent) {
this.buttonMode = true;
}

function etatOut(evt:MouseEvent) {
this.buttonMode = false;
}

// listener Button
clicPorte.addEventListener(MouseEvent.MOUSE_DOWN,lance)
clicPorte.addEventListener(MouseEvent.MOUSE_OVER,etatOver)
clicPorte.addEventListener(MouseEvent.MOUSE_OUT,etatOut)



On 4 déc, 14:29, "Cédric Tabin" <tabin.ced...@gmail.com> wrote:
> Hello,
>
> You must wait that the file are loaded... How do you create the files and
> when do you execute this code ?
>
> Regards,
> Cedric
>
> On Thu, Dec 4, 2008 at 12:30 PM, Ludovic Roux <l...@since76.com> wrote:
> > Hello everybody,In first, sorry my english...
>
> > So, I am trying Masapi for a Full Flash website, with a lot of animations,
> > sounds, etc...
> > I can load all the files and see them.
> > But I can't control them.
>
> > Exemple
>
> > Index.swf :
>
> > //get files
> > var file1:ILoadableFile = cml.getFileAt(0); // png
> > var file2:ILoadableFile = cml.getFileAt(1); // swf
> > var file3:ILoadableFile = cml.getFileAt(2); // swf with a button
> > var file4:ILoadableFile = cml.getFileAt(3); // swf
> > var file5:ILoadableFile = cml.getFileAt(4); // swf
>
> > //get files into a Loader
> > var ldr:Loader = file1.getData("flash.display.Loader");
> > var ldr2:Loader = file2.getData("flash.display.Loader");
> > var ldr3:Loader = file3.getData("flash.display.Loader");
> > var ldr4:Loader = file4.getData("flash.display.Loader");
> > var ldr5:Loader = file5.getData("flash.display.Loader");
>
> > addChild(ldr); //
> > addChild(ldr2); //
> > addChild(ldr3); //
> > addChild(ldr4); //
> > addChild(ldr5); //
> > *
> > *
> > *Explication :*
>
> > When I press my button into *ldr3*, I want to control ldr4 (visible =
> > false).
> > I try to check the target with this code into *ldr3* :
>
> > *trace(root)*
> > *trace(root.parent)*
> > *trace(parent)*
> > *trace(root.parent.root);*
> > *
> > *
> > I have :
> > *
> > *
> > *[object MainTimeline]
> > [object Loader]
> > [object Loader]
> > null
>
> > I think my target is not correct (null)
>
> > Thank you for your help and thanks for MASAPI
>
> > Ludo
>
> > *

Cédric Tabin

unread,
Dec 5, 2008, 5:37:49 AM12/5/08
to mas...@googlegroups.com
Hello,

Ok I just get it :) The problem is that your target is wrong. When you do root.parent, you become a Loader. You should do something like that :

var racine:DisplayObject = root.loaderInfo.loader.root

and you will get the root of your index.swf !

Regards,
Cedric

Ludo

unread,
Dec 8, 2008, 5:43:46 AM12/8/08
to masapi
Hello,

I find the problem. I can use :
var racine:DisplayObject = root.loaderInfo.loader.root or var racine =
root.parent.root

The problem was that chateau.swf (swf loaded) is not really 100%
loaded when it read the code. It can not find the target.

Solution :
Chateau.swf : I put the all the code in FRAME 2, with FRAME 1 to stop
();
index.swf (swf loader) : when I execute addChild, I tell chateau.swf
to go to FRAME 2.

It is good now.

But, I thought when the API go to FRAME 2, all the elements are
completly loaded....

Thank you

Cédric Tabin

unread,
Dec 8, 2008, 4:43:25 PM12/8/08
to mas...@googlegroups.com
Hello,

The fact is that your 'chateau.swf' is being played before all elements are loaded (and so the Loader is not put on the screen at that time). Currently you use directly LoadableFileType.SWF for loading your animations. If you want to avoid the 'automatic' playing of your swf, use the LoadableFileType.BINARY. As I see so far, your code doesn't need to be changed anyware, just for this constants and all will works fine !

Regards,
Cedric

Ludo

unread,
Dec 10, 2008, 3:42:34 AM12/10/08
to masapi
Hello,

I am going to try. Thank you for you help Cédric.
See you.

Regards
Ludo
Reply all
Reply to author
Forward
0 new messages