Jump to content
GreenSock

Benjamin Waller

scaleMode issues with child swfs

Recommended Posts

Hello,

 

I'm having another go at trying to resolve this issue. The contents (mcs) of my child swfs are scaling up and I don't know how to fix it. Could anyone please help?

I have set scaleMode to "None" in the SWFLoader Vars see below.

 

swfs.append(new SWFLoader("pair1.swf", {container:container_mc, width:700, height:700,scaleMode:"none"}));
swfs.append(new SWFLoader("pair2.swf", {container:container_mc, width:700, height:700,scaleMode:"none"}));

 

The scaling problem happens after the swfs are loaded into the parent swf. They don't scale up when you run them separately.

Note: I've attached the basic files to be able to compile the parent swf. I didn't include the fla files of the 2 child swfs or Greensocks files to reduce the zip file size. Hope that enough to see where the problem may lie.

 

See the code from the first child swf below. The only difference with the second child swf, in code, is the sound files that are loaded.

import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import com.greensock.plugins.TweenPlugin;
import com.greensock.plugins.AutoAlphaPlugin;
import com.greensock.plugins.VisiblePlugin;

TweenPlugin.activate([AutoAlphaPlugin, VisiblePlugin]);

import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.Loader;
import com.greensock.events.TweenEvent;
import flash.display.MovieClip;
import flash.events.ActivityEvent;


this.Word1.visible = false;
this.Word2.visible = false;
this.cross1.visible = false;
this.cross2.visible = false;
this.tick1.visible = false;
this.tick2.visible = false;

this.cross1.alpha = 0;
this.cross2.alpha = 0;
this.tick1.alpha = 0;
this.tick2.alpha = 0;


////Greensock mp3Loader ////
var sound1:MP3Loader = new MP3Loader("sound/tick.mp3", {autoPlay:false});
var sound2:MP3Loader = new MP3Loader("sound/spring.mp3", {autoPlay:false});
var sound3:MP3Loader = new MP3Loader("sound/chào_Em.mp3", {autoPlay:false});
var sound4:MP3Loader = new MP3Loader("sound/chào_Anh.mp3", {autoPlay:false});
var currentLoader:SWFLoader;

//{onComplete:init}
var queue:LoaderMax = new LoaderMax({paused:true});

queue.append(sound1);
queue.append(sound2);
queue.append(sound3);
queue.append(sound4);
queue.load();


// ObjectsIn array holds all assets (except for the Word1 & Word2 2nd mcs) that tween on stage independently to start the activity
// ObkectsOut array holds all assets which tweens them to an Alpha of O when the activity is completed
var ObjectsIn:Array = [one, two, three, four, Target1, Target2];
var ObjectsOut:Array = [one, two, three, four, Target1, Target2, Word1, Word2];
var mainIn:TimelineMax = new TimelineMax({{paused:true, delay:2}); // 
var mainOut:TimelineMax = new TimelineMax({paused:true});

mainIn.appendMultiple(TweenMax.allFrom(ObjectsIn, 3, {autoAlpha:0}));// all Obj are tweened on stage after 3 seconds 
mainIn.append(TweenLite.from(Word1, 0.2, {autoAlpha:0, onComplete:play1stSound}), 1); 

mainOut.appendMultiple(TweenMax.allTo(ObjectsOut, 3, {autoAlpha:0}), 3); // all Obj are tweened off stage after 3 seconds

var Tick1:TimelineLite = new TimelineLite({paused:true});
var Tick2:TimelineLite = new TimelineLite({paused:true});
var Cross1:TimelineLite = new TimelineLite({paused:true});
var Cross2:TimelineLite = new TimelineLite({paused:true}); 



Tick1.append( new TweenLite(tick1, 1.2, {autoAlpha:1, onComplete:ReverseTick1}));
Tick2.append( new TweenLite(tick2, 1.2, {autoAlpha:1, onComplete:ReverseTick2}));
Cross1.append( new TweenLite(cross1, 1.2, {autoAlpha:1, onComplete:ReverseCross1}));
Cross2.append( new TweenLite(cross2, 1.2, {autoAlpha:1, onComplete:ReverseCross2}));

//Event Listeners for the 2 containers that are clickable with a glow filter ///
one.buttonMode = true; 
two.buttonMode = true; 
//Word1.invisBut.buttonMode = true;
one.addEventListener(MouseEvent.ROLL_OVER, objOver);
two.addEventListener(MouseEvent.ROLL_OVER, objOver);
one.addEventListener(MouseEvent.ROLL_OUT, objOut);
two.addEventListener(MouseEvent.ROLL_OUT, objOut);

//Event Listeners for sound icons that are clickable ///
Word1.soundIcon1.addEventListener(MouseEvent.CLICK, play1stWordSound);
Word2.soundIcon2.addEventListener(MouseEvent.CLICK, play2ndWordSound);
three.soundIcon3.addEventListener(MouseEvent.CLICK, play1stWordSound);
four.soundIcon4.addEventListener(MouseEvent.CLICK, play2ndWordSound);


/// Glow function for current target to show user which buttons can be selected/////
function objOver(e:MouseEvent):void{

   var currentMC:MovieClip = MovieClip(e.target);
   //TweenMax.to(currentMC, .3, {colorMatrixFilter:{saturation:1, brightness:1}});
   TweenMax.to(currentMC, 0, {glowFilter:{color:0xffffff, alpha:1, blurX:40, blurY:40}});

   }

function objOut(e:MouseEvent):void{

   var currentMC:MovieClip = MovieClip(e.target);
   //TweenMax.to(currentMC, 1, {colorMatrixFilter:{saturation:.1, brightness:.5}});
   TweenMax.to(currentMC, 0, {glowFilter:{color:0xffffff, alpha:0, blurX:40, blurY:40}});
}  

///Button Sequencer Class /////// by Jody Hall

var buttonArray:Array = [one, two];

var enforcer:ButtonSequencer = new ButtonSequencer(buttonArray);

enforcer.addEventListener(ButtonSequencer.CORRECT, correct_onClick);
enforcer.addEventListener(ButtonSequencer.INCORRECT, incorrect_onClick);

// Sound 1 loaded
function play1stSound():void{
trace("first sound played from child swf 1"); 
//sound3.gotoSoundTime(0,true);
sound3.playSound();

}

/// This function shows ticks, plays sound for correct selections & tweens the correct word into place on the matching pictures////
function correct_onClick(event:Event):void {
trace("correct");
if(enforcer.lastClicked == one) {
	trace("one clicked");
	//tween the correct word into position
	TweenLite.to(Word1, 1, {x:Target1.x, y:Target1.y, ease:Quad.easeInOut, onComplete:DelayCall});
	Tick1.play();// show the tick graphic
	enforcer.enabled = false;
} else if(enforcer.lastClicked == two) {
	trace("two clicked");
	 // tween the correct word into position
	TweenLite.to(Word2, 1, {x:Target2.x, y:Target2.y, ease:Quad.easeInOut});
	Tick2.play(); // tween the tick graphic
	TweenLite.to(Word1, 2, {autoAlpha:1}); // retween Word1 visible
	this.Word1.soundIcon1.visible = false;
	mainOut.play(); //tween all ojbs on stage (except anh_word) and waits 4 sec and Alpha's out.
	//firstWordOut.play()
	enforcer.enabled = false;
}

 sound1.playSound();///play sound for correct
 sound1.gotoSoundTime(0,true);
}
//// This function shows incorrect clicks for both wrong selections. 
function incorrect_onClick(event:Event):void {
trace("sorry, try again");
if(enforcer.lastClicked == one) {
	trace("one clicked");
	Cross1.play();
	sound2.playSound();///play sound for incorrect
	sound2.addEventListener(Event.SOUND_COMPLETE, done1);
} else if(enforcer.lastClicked == two) {
	trace("two clicked");
	Cross2.play();
	sound2.playSound();
	sound2.addEventListener(Event.SOUND_COMPLETE, done2)
}
sound2.gotoSoundTime(0,true);
}

function done1(e:Event):void{
trace("done playing sound1 now wait");
TweenLite.delayedCall(0.2, playNextSound1)
//kill any delayed calles to playNextSound
TweenLite.killTweensOf(playNextSound2);
//pause sound2 incase it is playing
 sound3.pauseSound();
}	

function playNextSound1(){
trace("let's play the next sound");
sound4.gotoSoundTime(0,true);
}	
function done2(e:Event):void{
trace("done playing sound1 now wait");
TweenLite.delayedCall(0.2, playNextSound2)
TweenLite.killTweensOf(playNextSound1);
sound4.pauseSound();
}	

function playNextSound2(){
trace("let's play the next sound");
sound3.gotoSoundTime(0,true);
}	

function DelayCall(){
TweenLite.delayedCall(2, SetUpNextWord)


}
function SetUpNextWord(){
TweenLite.to(Word1, 2, {autoAlpha:0});// fade out 1st word
TweenLite.to(Word2, 2, {autoAlpha:1});// fade in 2nd word
enforcer.enabled = true;
trace("second sounds for second word played"); 
sound4.gotoSoundTime(0,true);
}

function ReverseTick1(){
	Tick1.reverse();// fade out the tick graphic 1
	one.buttonMode = false; 
	}
function ReverseTick2(){
	two.buttonMode = false; 
	Tick2.reverse(); // fade out the tick graphic 2
	}
function ReverseCross1(){
	Cross1.reverse();// fade out the cross graphic 1
	queue.load();
	}
function ReverseCross2(){
	Cross2.reverse(); //fade out the cross graphic 2
	queue.load();
	}


function play1stWordSound(event:Event){
	//enforcer.enabled = true;
	trace("sound played from 1st Word"); 
	sound3.gotoSoundTime(0,true);

}


function play2ndWordSound(event:Event){
	//enforcer.enabled = true;
	trace("sound played from 2nd Word"); 
	sound4.gotoSoundTime(0,true);

}


function swfComplete(){
trace("Activity complete");
var parentMovie:MovieClip = this.parent.parent as MovieClip;
parentMovie.timelineCompleteMessage();
//currentLoader.rawContent.startTimelineMax(); 
}
function notifyParent(){
var parentMovie:MovieClip = this.parent.parent as MovieClip;
parentMovie.timelineStartMessage();
}

Link to comment
Share on other sites

in MainSWFLoader.fla the container symbol is scaled awkwardly on the stage. select the container_mc and look in the transform panel it has horizontal scale of 120% and vertical scale of 205%.

reset container_mc to its native size and it should work fine.

 

-c

Link to comment
Share on other sites

Thanks Carl,

 

That has fixed the scaling problem but now the swf isn't positioned in the center of the container when loaded, It is offset to the right and lower than center. Any reason for that?

Each swf has a stage size of 700x700 px that matches the container_mc but the assets are not wrapped in any outer mc they are mcs that are just positioned on that stage where I want them to appear.

 

Ben

Link to comment
Share on other sites

Just move the container so that it's registration point is where you want the top left corner of your

Loaded swf to be.

Link to comment
Share on other sites

Thanks Carl,

 

Worked a charm. Didn't think to look at registration points.

 

Cheers,

Ben

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×