hanzi
August 4th, 2008, 09:16 AM
Hey
I have two questions actually.
First: I have background that scales to the window size and content loaded over it that also scales, but when I click on the maximize button on the window my content does not scale along with the background...don't know why.
Second: I finally found a cool image gallery app at www.flashOtaku.com (http://www.flashotaku.com). the only thing is that I want to load separate xml files on separate buttons but I can't seem to get that right either...my class will perhaps give somebody smarter than me a better idea of what is goin on...
thanx for any help....you can check the site here to see what happens with the class as it is now. www.crystal-concept.com (http://www.crystal-concepts.com) Please be patient, I'm still working on a preloader
Thanx again
package
{
import flash.display.DisplayObject;
import flash.display.SpreadMethod;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.ContextMenuEvent;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;
import flash.events.TimerEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.ui.Mouse;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import caurina.transitions.Tweener;
import com.flashotaku.slideshow.Slideshow;
import com.flashotaku.thumbnailscroller.ThumbnailScroller ;
import com.flashotaku.thumbnailscroller.events.ThumbnailE vent;
import com.flashotaku.slideshow.events.SlideshowEvent;
import flash.utils.Timer;
import gs.TweenMax;
public class main extends Sprite
{
public static var origW:Number = 1024 //original stage width
public static var origH:Number = 768 //original stage height
//graphic resources
private var bg:Sprite;
private var cont:Sprite;
private var art:Sprite;
private var photo:Sprite;
private var project:Sprite;
//constructor
public function main ()
{
//Tel the player not to scale the assets
stage.scaleMode = StageScaleMode.NO_SCALE;
//Tell the player to put co-ords 0,0 to the top left corner
stage.align = StageAlign.TOP_LEFT;
//Listen for resize events
stage.addEventListener(Event.RESIZE, onResize);
//Create and add body resource to the display list
bg = new bg_mc();
addChild(bg);
cont = new content();
addChild(cont);
art = new art_mc();
cont.addChild(art);
art.x = 94.2;
art.y = 512.5;
photo = new photo_mc();
cont.addChild(photo);
photo.x = 136.1;
photo.y = 517.9;
project = new project_mc();
cont.addChild(project);
project.x = 150;
project.y = 535;
//Size everything after creation to insure the app is drawn
//properly the first time it is seen prior to any user initiated
//resizing
onResize(null);
art.addEventListener(MouseEvent.CLICK, ClickListener)
photo.addEventListener(MouseEvent.CLICK, ClickListener1)
project.addEventListener(MouseEvent.CLICK, ClickListener2)
//set button properties
art.buttonMode = true;
art.useHandCursor = true;
photo.buttonMode = true;
photo.useHandCursor = true;
project.buttonMode = true;
project.useHandCursor = true;
var box:Sprite = new Sprite;
var imageBox:Sprite = new Sprite;
var mySlideshow:Slideshow;
var myScroller:ThumbnailScroller;
var init:Boolean;
//whatclick function
function whatClick(event:MouseEvent):void
{
if (event.currentTarget == art)
{
// return "images.xml";
myScroller.xmlPath = "thumbnails.xml";
trace("art clicked");
}
else if (event.currentTarget == photo)
{
// return "images1.xml";
myScroller.xmlPath = "thumbnails1.xml";
trace("photo clicked");
}
else if (event.currentTarget == project)
{
// return "images2.xml";
myScroller.xmlPath = "thumbnails2.xml";
trace("project clicked");
}
}
art.addEventListener(MouseEvent.CLICK, whatClick);
photo.addEventListener(MouseEvent.CLICK, whatClick);
project.addEventListener(MouseEvent.CLICK, whatClick);
//gallery functions
function loadGallery()
{
mySlideshow = new Slideshow();
mySlideshow.xmlPath = "images.xml";
mySlideshow.autoLoad = false;
mySlideshow.setSize(500, 420);
mySlideshow.x = 476.5;
mySlideshow.y = 27.5;
mySlideshow.setBorder = false;
mySlideshow.preloaderType = "circular";
mySlideshow.transitionEffect = "fade";
}
function loadThumb()
{
myScroller = new ThumbnailScroller();
cont.addChild(myScroller);
myScroller.xmlPath = "thumbnails.xml";
myScroller.setSize(920, 70);
myScroller.x = 50;
myScroller.y = 650;
myScroller.setBorder = true;
myScroller.borderThickness = 2;
myScroller.easingType = "Back";
myScroller.easingMethod = "easeInOut";
myScroller.moveAmount = 100;
myScroller.mouseMove = true;
myScroller.name = "myScroller";
myScroller.addEventListener(ThumbnailEvent.CLICK, clickHandler);
myScroller.addEventListener(ThumbnailEvent.THUMB_I NIT, addBlur);
myScroller.addEventListener(ThumbnailEvent.MOUSE_O VER, rollOverBlur);
myScroller.addEventListener(ThumbnailEvent.MOUSE_O UT, rollOutBlur);
}
//thumbnail functions
function clickHandler(event:ThumbnailEvent):void
{
if(!init)
{
init = true;
cont.addChild(mySlideshow);
mySlideshow.loadImage(event.item.id);
trace(event.item.id);
}
mySlideshow.loadImage(event.item.id);
}
function addBlur(event:ThumbnailEvent)
{
TweenMax.to(event.item.child, 0.5, {alpha:1});
}
function rollOverBlur(event:ThumbnailEvent)
{
TweenMax.to(event.item.child, 0.5, {alpha:0.1});
}
function rollOutBlur(event:ThumbnailEvent)
{
TweenMax.to(event.item.child, 0.5, {alpha:1});
}
//delet child function
function deleteChild():void
{
cont.removeChild(myScroller);
trace("trying to remove child");
if (Boolean(cont.getChildByName('myScroller')))
{
trace("child removed");
}
else
{
trace("child not removed");
}
}
//tween functions
function tweenBoxIn():void
{
TweenMax.multiSequence
([
{ target:box, time:0.2, y:625 },
{ target:box, time:0.5, scaleY:12 },
{ target:box, time:1, x:35, scaleX:95, onComplete:loadThumb }
]);
}
function tweenIBoxIn():void
{
TweenMax.multiSequence
([
{ target:imageBox, time:0.5, x:466 },
{ target:imageBox, time:0.1, alpha:0.8 },
{ target:imageBox, time:1, scaleX:52 },
{ target:imageBox, time:1, y:15, scaleY:44.4, onComplete:loadGallery }
]);
}
function tweenBoxAgain():void
{
TweenMax.multiSequence
([
{ target:myScroller, time:1, alpha:0 },
{ target:myScroller, onComplete:deleteChild },
{ target:box, time:0.5, y:860 },
{ target:box, time:1, y:625 },
{ target:box, onComplete:loadThumb }
]);
}
//Check ClickListener
function ClickListener(event:MouseEvent):void
{
art.mouseEnabled = false;
photo.mouseEnabled = true;
project.mouseEnabled = true;
trace("button clicked:" + event.currentTarget);
if (Boolean(cont.getChildByName('box')))
{
trace("box found");
tweenBoxAgain();
}
else
{
trace("no boxes found");
box = new Sprite();
box.graphics.lineStyle(2, 0xffffff, 0.5, false, "none");
box.graphics.beginFill(0x000000, 0.5);
box.graphics.drawRect(0, 0, 10, 10);
box.graphics.endFill();
cont.addChild(box);
box.name = "box";
trace("new box drawn");
imageBox = new Sprite();
imageBox.graphics.lineStyle(2, 0xffffff, 0.5, false, "none");
imageBox.graphics.beginFill(0x000000, 0.5);
imageBox.graphics.drawRect(0, 0, 10, 10);
imageBox.graphics.endFill();
cont.addChild(imageBox);
tweenBoxIn();
tweenIBoxIn();
trace("new imageBox drawn");
}
}
//Check ClickListener1
function ClickListener1(event:MouseEvent):void
{
art.mouseEnabled = true;
photo.mouseEnabled = false;
project.mouseEnabled = true;
trace("button clicked:" + event.currentTarget);
if (Boolean(cont.getChildByName('box')))
{
trace("box found");
tweenBoxAgain();
}
else
{
trace("no boxes found");
box = new Sprite();
box.graphics.lineStyle(2, 0xffffff, 0.5, false, "none");
box.graphics.beginFill(0x000000, 0.5);
box.graphics.drawRect(0, 0, 10, 10);
box.graphics.endFill();
cont.addChild(box);
box.name = "box";
trace("new box drawn");
imageBox = new Sprite();
imageBox.graphics.lineStyle(2, 0xffffff, 0.5, false, "none");
imageBox.graphics.beginFill(0x000000, 0.5);
imageBox.graphics.drawRect(0, 0, 10, 10);
imageBox.graphics.endFill();
cont.addChild(imageBox);
tweenBoxIn();
tweenIBoxIn();
trace("new imageBox drawn");
}
}
//Check ClickListener2
function ClickListener2(event:MouseEvent):void
{
art.mouseEnabled = true;
photo.mouseEnabled = true;
project.mouseEnabled = false;
trace("button clicked:" + event.currentTarget);
if (Boolean(cont.getChildByName('box')))
{
trace("box found");
tweenBoxAgain();
}
else
{
trace("no boxes found");
box = new Sprite();
box.graphics.lineStyle(2, 0xffffff, 0.5, false, "none");
box.graphics.beginFill(0x000000, 0.5);
box.graphics.drawRect(0, 0, 10, 10);
box.graphics.endFill();
cont.addChild(box);
box.name = "box";
trace("new box drawn");
imageBox = new Sprite();
imageBox.graphics.lineStyle(2, 0xffffff, 0.5, false, "none");
imageBox.graphics.beginFill(0x000000, 0.5);
imageBox.graphics.drawRect(0, 0, 10, 10);
imageBox.graphics.endFill();
cont.addChild(imageBox);
tweenBoxIn();
tweenIBoxIn();
trace("new imageBox drawn");
}
}
}
//listening for stage resize
public function onResize(event:Event):void
{
//get the new stage height
var sw:Number = stage.stageWidth;
var sh:Number = stage.stageHeight;
//then update the children with this new size
bg.height = sh;
bg.width = sw;
cont.height = sh;
cont.width = sw;
}
}
}
I have two questions actually.
First: I have background that scales to the window size and content loaded over it that also scales, but when I click on the maximize button on the window my content does not scale along with the background...don't know why.
Second: I finally found a cool image gallery app at www.flashOtaku.com (http://www.flashotaku.com). the only thing is that I want to load separate xml files on separate buttons but I can't seem to get that right either...my class will perhaps give somebody smarter than me a better idea of what is goin on...
thanx for any help....you can check the site here to see what happens with the class as it is now. www.crystal-concept.com (http://www.crystal-concepts.com) Please be patient, I'm still working on a preloader
Thanx again
package
{
import flash.display.DisplayObject;
import flash.display.SpreadMethod;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.ContextMenuEvent;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;
import flash.events.TimerEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.ui.Mouse;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import caurina.transitions.Tweener;
import com.flashotaku.slideshow.Slideshow;
import com.flashotaku.thumbnailscroller.ThumbnailScroller ;
import com.flashotaku.thumbnailscroller.events.ThumbnailE vent;
import com.flashotaku.slideshow.events.SlideshowEvent;
import flash.utils.Timer;
import gs.TweenMax;
public class main extends Sprite
{
public static var origW:Number = 1024 //original stage width
public static var origH:Number = 768 //original stage height
//graphic resources
private var bg:Sprite;
private var cont:Sprite;
private var art:Sprite;
private var photo:Sprite;
private var project:Sprite;
//constructor
public function main ()
{
//Tel the player not to scale the assets
stage.scaleMode = StageScaleMode.NO_SCALE;
//Tell the player to put co-ords 0,0 to the top left corner
stage.align = StageAlign.TOP_LEFT;
//Listen for resize events
stage.addEventListener(Event.RESIZE, onResize);
//Create and add body resource to the display list
bg = new bg_mc();
addChild(bg);
cont = new content();
addChild(cont);
art = new art_mc();
cont.addChild(art);
art.x = 94.2;
art.y = 512.5;
photo = new photo_mc();
cont.addChild(photo);
photo.x = 136.1;
photo.y = 517.9;
project = new project_mc();
cont.addChild(project);
project.x = 150;
project.y = 535;
//Size everything after creation to insure the app is drawn
//properly the first time it is seen prior to any user initiated
//resizing
onResize(null);
art.addEventListener(MouseEvent.CLICK, ClickListener)
photo.addEventListener(MouseEvent.CLICK, ClickListener1)
project.addEventListener(MouseEvent.CLICK, ClickListener2)
//set button properties
art.buttonMode = true;
art.useHandCursor = true;
photo.buttonMode = true;
photo.useHandCursor = true;
project.buttonMode = true;
project.useHandCursor = true;
var box:Sprite = new Sprite;
var imageBox:Sprite = new Sprite;
var mySlideshow:Slideshow;
var myScroller:ThumbnailScroller;
var init:Boolean;
//whatclick function
function whatClick(event:MouseEvent):void
{
if (event.currentTarget == art)
{
// return "images.xml";
myScroller.xmlPath = "thumbnails.xml";
trace("art clicked");
}
else if (event.currentTarget == photo)
{
// return "images1.xml";
myScroller.xmlPath = "thumbnails1.xml";
trace("photo clicked");
}
else if (event.currentTarget == project)
{
// return "images2.xml";
myScroller.xmlPath = "thumbnails2.xml";
trace("project clicked");
}
}
art.addEventListener(MouseEvent.CLICK, whatClick);
photo.addEventListener(MouseEvent.CLICK, whatClick);
project.addEventListener(MouseEvent.CLICK, whatClick);
//gallery functions
function loadGallery()
{
mySlideshow = new Slideshow();
mySlideshow.xmlPath = "images.xml";
mySlideshow.autoLoad = false;
mySlideshow.setSize(500, 420);
mySlideshow.x = 476.5;
mySlideshow.y = 27.5;
mySlideshow.setBorder = false;
mySlideshow.preloaderType = "circular";
mySlideshow.transitionEffect = "fade";
}
function loadThumb()
{
myScroller = new ThumbnailScroller();
cont.addChild(myScroller);
myScroller.xmlPath = "thumbnails.xml";
myScroller.setSize(920, 70);
myScroller.x = 50;
myScroller.y = 650;
myScroller.setBorder = true;
myScroller.borderThickness = 2;
myScroller.easingType = "Back";
myScroller.easingMethod = "easeInOut";
myScroller.moveAmount = 100;
myScroller.mouseMove = true;
myScroller.name = "myScroller";
myScroller.addEventListener(ThumbnailEvent.CLICK, clickHandler);
myScroller.addEventListener(ThumbnailEvent.THUMB_I NIT, addBlur);
myScroller.addEventListener(ThumbnailEvent.MOUSE_O VER, rollOverBlur);
myScroller.addEventListener(ThumbnailEvent.MOUSE_O UT, rollOutBlur);
}
//thumbnail functions
function clickHandler(event:ThumbnailEvent):void
{
if(!init)
{
init = true;
cont.addChild(mySlideshow);
mySlideshow.loadImage(event.item.id);
trace(event.item.id);
}
mySlideshow.loadImage(event.item.id);
}
function addBlur(event:ThumbnailEvent)
{
TweenMax.to(event.item.child, 0.5, {alpha:1});
}
function rollOverBlur(event:ThumbnailEvent)
{
TweenMax.to(event.item.child, 0.5, {alpha:0.1});
}
function rollOutBlur(event:ThumbnailEvent)
{
TweenMax.to(event.item.child, 0.5, {alpha:1});
}
//delet child function
function deleteChild():void
{
cont.removeChild(myScroller);
trace("trying to remove child");
if (Boolean(cont.getChildByName('myScroller')))
{
trace("child removed");
}
else
{
trace("child not removed");
}
}
//tween functions
function tweenBoxIn():void
{
TweenMax.multiSequence
([
{ target:box, time:0.2, y:625 },
{ target:box, time:0.5, scaleY:12 },
{ target:box, time:1, x:35, scaleX:95, onComplete:loadThumb }
]);
}
function tweenIBoxIn():void
{
TweenMax.multiSequence
([
{ target:imageBox, time:0.5, x:466 },
{ target:imageBox, time:0.1, alpha:0.8 },
{ target:imageBox, time:1, scaleX:52 },
{ target:imageBox, time:1, y:15, scaleY:44.4, onComplete:loadGallery }
]);
}
function tweenBoxAgain():void
{
TweenMax.multiSequence
([
{ target:myScroller, time:1, alpha:0 },
{ target:myScroller, onComplete:deleteChild },
{ target:box, time:0.5, y:860 },
{ target:box, time:1, y:625 },
{ target:box, onComplete:loadThumb }
]);
}
//Check ClickListener
function ClickListener(event:MouseEvent):void
{
art.mouseEnabled = false;
photo.mouseEnabled = true;
project.mouseEnabled = true;
trace("button clicked:" + event.currentTarget);
if (Boolean(cont.getChildByName('box')))
{
trace("box found");
tweenBoxAgain();
}
else
{
trace("no boxes found");
box = new Sprite();
box.graphics.lineStyle(2, 0xffffff, 0.5, false, "none");
box.graphics.beginFill(0x000000, 0.5);
box.graphics.drawRect(0, 0, 10, 10);
box.graphics.endFill();
cont.addChild(box);
box.name = "box";
trace("new box drawn");
imageBox = new Sprite();
imageBox.graphics.lineStyle(2, 0xffffff, 0.5, false, "none");
imageBox.graphics.beginFill(0x000000, 0.5);
imageBox.graphics.drawRect(0, 0, 10, 10);
imageBox.graphics.endFill();
cont.addChild(imageBox);
tweenBoxIn();
tweenIBoxIn();
trace("new imageBox drawn");
}
}
//Check ClickListener1
function ClickListener1(event:MouseEvent):void
{
art.mouseEnabled = true;
photo.mouseEnabled = false;
project.mouseEnabled = true;
trace("button clicked:" + event.currentTarget);
if (Boolean(cont.getChildByName('box')))
{
trace("box found");
tweenBoxAgain();
}
else
{
trace("no boxes found");
box = new Sprite();
box.graphics.lineStyle(2, 0xffffff, 0.5, false, "none");
box.graphics.beginFill(0x000000, 0.5);
box.graphics.drawRect(0, 0, 10, 10);
box.graphics.endFill();
cont.addChild(box);
box.name = "box";
trace("new box drawn");
imageBox = new Sprite();
imageBox.graphics.lineStyle(2, 0xffffff, 0.5, false, "none");
imageBox.graphics.beginFill(0x000000, 0.5);
imageBox.graphics.drawRect(0, 0, 10, 10);
imageBox.graphics.endFill();
cont.addChild(imageBox);
tweenBoxIn();
tweenIBoxIn();
trace("new imageBox drawn");
}
}
//Check ClickListener2
function ClickListener2(event:MouseEvent):void
{
art.mouseEnabled = true;
photo.mouseEnabled = true;
project.mouseEnabled = false;
trace("button clicked:" + event.currentTarget);
if (Boolean(cont.getChildByName('box')))
{
trace("box found");
tweenBoxAgain();
}
else
{
trace("no boxes found");
box = new Sprite();
box.graphics.lineStyle(2, 0xffffff, 0.5, false, "none");
box.graphics.beginFill(0x000000, 0.5);
box.graphics.drawRect(0, 0, 10, 10);
box.graphics.endFill();
cont.addChild(box);
box.name = "box";
trace("new box drawn");
imageBox = new Sprite();
imageBox.graphics.lineStyle(2, 0xffffff, 0.5, false, "none");
imageBox.graphics.beginFill(0x000000, 0.5);
imageBox.graphics.drawRect(0, 0, 10, 10);
imageBox.graphics.endFill();
cont.addChild(imageBox);
tweenBoxIn();
tweenIBoxIn();
trace("new imageBox drawn");
}
}
}
//listening for stage resize
public function onResize(event:Event):void
{
//get the new stage height
var sw:Number = stage.stageWidth;
var sh:Number = stage.stageHeight;
//then update the children with this new size
bg.height = sh;
bg.width = sw;
cont.height = sh;
cont.width = sw;
}
}
}