Copy link to clipboard
Copied
Hello, please I have problem with my project. I'm glad for every help I can get.
so, my issue is this:
I have main.swf which defaultly loads menubar.swf, and footer.swf in menubar.swf are buttons: button1_btn, button2_btn, button3_btn.
Main.swf is listening if button 1, 2 or 3 is clicked. If so main.swf loads content1.swf, content2.swf or content3.swf
for example: user clicked button1_btn which addedChild of content1.swf that comes from left side to center of the stage, and if user going to click button2_btn I want the content which is loaded(in this example is it content1.swf), will go away from the stage to right side and then content2.swf will come from left side to the center of the stage.
I'm sorry for my english.
All help will be very appreciated.
Thanks so much in advance.
you're still changing the names of your buttons.
when you finally decide on your button names, add them to an array and use:
var buttonA:Array = [the button that corresponds to content1Loader, the buttons that corresponds to content2Loader, etc];
var prevOnStageLoader:Loader;
for(var i:int=0;i<buttonA.length;i++){
buttonA.addEventListener(MouseEvent.CLICK, goContent);
}
function goContent(e:MouseEvent):void
{
if(prevOnStageLoader){
TweenLite.to(prevOnStageLoader,1,{x:stage.stageWidth});
}
prevOnStageLoade
...Copy link to clipboard
Copied
what's the problem?
Copy link to clipboard
Copied
My problem is: I fully don't know how to make this.
Simply, clicking somebutton addschild of somecontent and if someone click on somebutton whatevercontentX go out and whatevercontentY comes here.
Copy link to clipboard
Copied
when a button is clicked:
1. tween your loader (if it has a non-null content property) stage right. when that completes
2. move your loader stage-left
3. load your next swf
4. when loading is complete, tween your loader to stage center.
Copy link to clipboard
Copied
Thanks for reply, I'll try it.
Copy link to clipboard
Copied
I forget to say I have something like this. (All SWFs are loaded while starting up the project.)
button1_btn.addEventListener(MouseEvent.CLICK, goContent1);
button2_btn.addEventListener(MouseEvent.CLICK, goContent2);
button3_btn.addEventListener(MouseEvent.CLICK, goContent3);
function goContent1(e:MouseEvent):void
{
addChild(content1Loader);
content1Loader.x = -1250; // out of the stage
TweenLite.to(content1Loader, 1, {x:0, ease:Elastic.easeInOut});
}
function goContent2(e:MouseEvent):void
{
addChild(content2Loader);
content2Loader.x = -1250; // out of the stage
TweenLite.to(content2Loader, 1, {x:0, ease:Elastic.easeInOut});
}
function goContent3(e:MouseEvent):void
{
addChild(content3Loader);
content3Loader.x = -1250; // out of the stage
TweenLite.to(content3Loader, 1, {x:0, ease:Elastic.easeInOut});
}
and my problem is that if you click button 1 content 1 comes to the stage, but if you then click button2 content2 comes to the stage and old content do not go anywhere and stay there, so on the stage are 2 contents.
And I want to make, if is some content on the stage, it should go away, and then new content can come.
Copy link to clipboard
Copied
use:
var prevOnStageLoader:Loader; button1_btn.addEventListener(MouseEvent.CLICK, goContent);
button2_btn.addEventListener(MouseEvent.CLICK, goContent);
button3_btn.addEventListener(MouseEvent.CLICK, goContent);
function goContent(e:MouseEvent):void
{
if(prevOnStageLoader){
TweenLite.to(prevOnStageLoader,1,{x:stage.stageWidth});
}
prevOnStageLoader=Loader(this["content"+e.currentTarget.name.substr(6,1)+"Loader"]);
addChild(prevOnStageLoader);
prevOnStageLoader.x = -1250; // out of the stage
TweenLite.to(prevOnStageLoader, 1, {x:0, ease:Elastic.easeInOut});
}
Copy link to clipboard
Copied
i'm not sure, i can use this code. i didn't explained my issue correctly. i need only code what is on most of flash websites i want change the content while going to: About us page, contact page, home page and so on.
So if i'm browsing about us page. and i want to go to the contact page: i need removechild of about us page(or any other page what is currently loaded) and then addchild of(for example) contact page.
i think that is some simple code or method what most programmers using.
something like this, but i don't know how to write it correctly
home_btn.addEventListener(MouseEvent.CLICK, goHome);
aboutUs_btn.addEventListener(MouseEvent.CLICK, goAboutUs);
contact_btn.addEventListener(MouseEvent.CLICK, goContact);
function goHome(e:MouseEvent):void
{
removeChild(whatever, variable loaded what is currently loaded content); // here i dont know
addChild(homeLoader); // (home.swf)
}
function goHome(e:MouseEvent):void
{
removeChild(whatever, variable loaded what is currently loaded content); // here i dont know
addChild(aboutUsLoader); // (aboutUs.swf)
}
function goHome(e:MouseEvent):void
{
removeChild(whatever, variable loaded what is currently loaded content); // here i dont know
addChild(contactLoader); // (contact.swf)
}
Copy link to clipboard
Copied
copy and test the code i suggested.
Copy link to clipboard
Copied
ok, but in your code is not written name of swf that should be loaded.
so i've renamed
prevOnStageLoader=Loader(this["content"+e.currentTarget.name.substr
to
prevOnStageLoader=Loader(this["contactLoader"+e.currentTarget.name.substr
and i got this error:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChild()
at MethodInfo-98()
ps. thanks for helping to me
Copy link to clipboard
Copied
use the button names you originally showed.
var prevOnStageLoader:Loader;
button1_btn.addEventListener(MouseEvent.CLICK, goContent);
button2_btn.addEventListener(MouseEvent.CLICK, goContent);
button3_btn.addEventListener(MouseEvent.CLICK, goContent);
function goContent(e:MouseEvent):void
{
if(prevOnStageLoader){
TweenLite.to(prevOnStageLoader,1,{x:stage.stageWidth});
}
prevOnStageLoader=Loader(this["content"+e.currentTarget.name.substr(6, 1)+"Loader"]);
addChild(prevOnStageLoader);
prevOnStageLoader.x = -1250; // out of the stage
TweenLite.to(prevOnStageLoader, 1, {x:0, ease:Elastic.easeInOut});
}
Copy link to clipboard
Copied
ok, now i have this:
// (in public class)
private var contentLoader:Loader = new Loader();
private var content1Loader:Loader = new Loader(); // sign up page
// (in constructor function)
var signUpRequest:URLRequest = new URLRequest("../swf/menubar.swf");
content1Loader.load(signUpRequest);
// (not in constructor, somewhere in my code)
// menuMc because of addEventListener is linking to button in else SWF
menuMc.signUp1_btn.addEventListener(MouseEvent.CLICK, goContent);
private function goContent(e:MouseEvent):void
{
if(contentLoader)
{
TweenLite.to(contentLoader, 1, {x:stage.stageWidth});
}
contentLoader = this("content" + e.currentTarget.name.substr(17, 1) + "Loader");
addChild(contentLoader);
contentLoader.x = -1250; // out of stage because of tween
TweenLite.to(contentLoader, 1, {x:0, ease:Elastic.easeInOut});
}
and i don't understand this line:
contentLoader = this("content" + e.currentTarget.name.substr(17, 1) + "Loader");
// contentLoaders name is: static word content + dynamic name of button(character number 17th, ?) + static word Loader
right?
so contentLoader will load content called content1Loader ??
Copy link to clipboard
Copied
you're still changing the names of your buttons.
when you finally decide on your button names, add them to an array and use:
var buttonA:Array = [the button that corresponds to content1Loader, the buttons that corresponds to content2Loader, etc];
var prevOnStageLoader:Loader;
for(var i:int=0;i<buttonA.length;i++){
buttonA.addEventListener(MouseEvent.CLICK, goContent);
}
function goContent(e:MouseEvent):void
{
if(prevOnStageLoader){
TweenLite.to(prevOnStageLoader,1,{x:stage.stageWidth});
}
prevOnStageLoader=Loader(this["content"+(1+buttonA.indexOf(e.currentTarget))+"Loader"]);
addChild(prevOnStageLoader);
prevOnStageLoader.x = -1250;
TweenLite.to(prevOnStageLoader, 1, {x:0, ease:Elastic.easeInOut});
}
Copy link to clipboard
Copied
kglad thanks soo much now it works. I've tryed it in blank document with timeline code.
and now i'll only edit it to class code.
It's exactly that i want
Full code here:
import flash.display.*;
import com.greensock.*;
import com.greensock.easing.*;
import flash.net.URLRequest;
import flash.net.URLLoader;
var signUpUrl:URLRequest = new URLRequest("../swf/signUp.swf");
var logInUrl:URLRequest = new URLRequest("../swf/logIn.swf");
var content1Loader:Loader = new Loader();
var content2Loader:Loader = new Loader();
content1Loader.load(signUpUrl);
content2Loader.load(logInUrl);
var buttonA:Array = [signUp_btn, logIn_btn];
var prevOnStageLoader:Loader;
for(var i:int=0;i<buttonA.length;i++){
buttonA.addEventListener(MouseEvent.CLICK, goContent);
}
function goContent(e:MouseEvent):void
{
if(prevOnStageLoader){
TweenLite.to(prevOnStageLoader,1,{x:stage.stageWidth});
}
prevOnStageLoader=Loader(this["content"+(1+buttonA.indexOf(e.currentTarget))+"Loader"]);
addChild(prevOnStageLoader);
prevOnStageLoader.x = -1250;
TweenLite.to(prevOnStageLoader, 1, {x:0, ease:Elastic.easeInOut});
}
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now