Hi all,
I’m struggling to get this working.
At the moment the AS opens a fullProjectPanel when I click on one of the ProjectPanels. However, when I click on another ProjectPanel, the script just drags the same fullProjectPanel from library.
How do I get the script to load a “different” fullProjectPanel, i.e. the same library item, but containing different text and image, depending on what ProjectPanel I click.
Do I have to name each ProjectPanel and then use switch and case? I’m not sure how to tackle this.
Sorry if this sounds a bit confusing, but let me show you my scripts:
Cheers.
fullProjectPanel AS:
import com.greensock.TweenLite;
var fullProjectPanel:FullProjectPanel;
// ADD FULL PROJECT PANEL ( runs when clicking on project panel(2nd frame of mainContainer, line 28))
function addFullPanel():void {
fullProjectPanel = new FullProjectPanel;
//panelItem.name = imageName;
TweenLite.from(fullProjectPanel, 0.6, {alpha:0, delay:0.5});
addChild(fullProjectPanel);
// indicate state
fullProjectPanelUp = true;
// listen for click on close button
fullProjectPanel.closePanel.addEventListener(MouseEvent.CLICK, onCloseClick);
fullProjectPanel.closePanel.buttonMode = true;
}
function onCloseClick(evt:MouseEvent):void {
// run the slide up function that slides up the project container
mainContainer.slideUp();
// remove the panel
removeChild(fullProjectPanel);
// delay the state change to allow for transition
TweenLite.delayedCall(0.4, upFalse);
}
function upFalse():void {
fullProjectPanelUp = false;
}
Pretty obvious this’ll load an identical fullProjectPanel each time right.
The ProjectPanel AS reads:
import com.greensock.TweenLite;
import com.greensock.easing.Back;
import com.greensock.loading.*;
import com.greensock.loading.display.*;
import com.greensock.events.LoaderEvent;
import flash.display.Sprite;
import flash.text.*;
import flash.display.BitmapData;
import flash.display.Bitmap;
// CONTAINER FOR SCROLLING
var panelContainer:Sprite = new Sprite;
addChild(panelContainer);
// INITIAL VARIABLES
var imageArray:Array = new Array();
var currentButton:Object = new Object;
var selectedSection:Number = 0;
var myImage:Array = new Array();
function progressHandler(event:LoaderEvent):void {
trace("progress: " + event.target.progress);
}
var xmlLoader:URLLoader = new URLLoader();
var xmlData: XML;
//Load the XML file
xmlLoader.load(new URLRequest("images/slides2.xml"));
//Adding an event listener to notify when loading is completed
xmlLoader.addEventListener(Event.COMPLETE,ParseXML);
//xmlLoader.addEventListener(Event.COMPLETE,ParseXML2);
function ParseXML(event:Event):void {
//function ParseXML(xmlData:XML):void {
var panelArray:Array = new Array();
xmlData = new XML(event.target.data);
var lengthDoc = xmlData.image.name.length();
for (var j:int=0; j<lengthDoc; j++) {
var xmlLoader = new Loader();
var panelItem:ProjectPanel = new ProjectPanel;
var imageName = (xmlData.image[j].name);
// trace ("imageName = "+imageName);
// panelItem.addListeners();
panelItem.name = imageName;
panelItem.addEventListener(MouseEvent.CLICK, onClick);
panelItem.project_title.text = (xmlData.image[j].description.@title);
panelItem.project_description.text = (xmlData.image[j].description);
var imageThumb:String = xmlData.image[j].path.@thumb.toString();
myImage[j] = imageThumb;
trace (myImage[j]);
var imageUrlRequest:URLRequest = new URLRequest(myImage[j]);
imageArray[j] = xmlLoader.load(imageUrlRequest);
imageArray.push(xmlLoader);
panelItem.project_image.MovieClip = (imageArray[j+1]);
panelItem.project_image.addChild(imageArray[j+1]);
if (j>0) {
panelItem.x = j*(panelArray[j-1].width+10);
//trace("Image = "+imageInfo);
//var imageChildren:XMLList = event.image.children();
}
panelArray.push(panelItem);
// adding Items as children to Container
panelContainer.addChild(panelItem);
}
}
function ParseXML2(imageData2:XML):void {
trace("------------------------");
trace("XML Output");
trace("------------------------");
var imageChildren:XMLList = imageData2.image.children();
for each (var imageData2:XML in imageChildren) {
if (imageData2.name() == "name") {
// trace(imageData2);
}
}
}
function errorHandler(event:LoaderEvent):void {
trace("error occured with " + event.target + ": " + event.text);
}
function onClick(evt:MouseEvent):void {
// tween all panels below visible area when clicking on projectPanel
TweenLite.to(panelContainer, 0.5, {y:stage.stageHeight+250, ease:Back.easeIn});
// running function on the main timeline
MovieClip(this.parent).addFullPanel();
}
// slide the panels back up on closing the single panel project
function slideUp():void {
TweenLite.to(panelContainer, 0.5, {y:0, ease:Back.easeOut});
}
// HORIZONTAL SCROLLING
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
function onMove(evt:MouseEvent):void {
// scroll only if fullprojectpanelup is false to prevent from interfering with transitions
if (MovieClip(this.parent).fullProjectPanelUp==false) {
TweenLite.to(panelContainer, 0.3, {x:-(stage.mouseX/980)*panelContainer.width+stage.stageWidth/2});
}
}
stop();