RemoveChild issue
Hi All,
Got this code loading thumbs, and when their clicked loads a
bigger image etc...
function xmlLoaded (e:Event):void {
xml = XML(e.target.data);
images = xml.image;
for(var i:uint=0; i<images.length();i++){
var thumb:MovieClip = new MovieClip();
var thumbLoader:Loader = new Loader();
thumb.x = 65*i + spacing;
thumb.y = 370;
thumb.src = images[counter].@url;
thumb.mouseChildren = false;
thumb.buttonMode = true;
thumbLoader.load(new URLRequest(images[counter].@thumb));
addChild(thumb);
thumb.alpha = 0;
TweenMax.to(thumb, 1, {alpha:1, ease:Sine.easeIn});
thumb.addChild(thumbLoader);
thumbLoader.x = 24;
thumbLoader.y = -14;
thumb.addEventListener(MouseEvent.CLICK, clickedThumb);
counter++;
loader.load(new URLRequest(images[0].@url));
Problem happens with the following code - I go into
fullScreen and want to either hide the thumb etc... or remove it:
masker.addEventListener(MouseEvent.CLICK, fullScreen);
function fullScreen(MouseEvent):void
thumb.visible = false; // do not work
removeChild(thumb); // do not work
stage.displayState = StageDisplayState.FULL_SCREEN;
masker.x=0;
masker.y=0;
masker.width=stage.stageWidth;
masker.height=stage.stageHeight;
StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
masker.buttonMode = true;
Hope someone can provide an answer to this, as it's driving
me BONKERS ;) It's got to be down to how I am referring to it, the
path.
Kind Regards,
Boxing Boom
I can see a few possible problems. One is that if you want to
reference a variable you create from multiple functions it needs to
be declared outside both functions. Such as reference 1 below.
Another is if you are creating many objects creating the same
variable you should add them to an array to be able to access them
later as below in reference 2.
Note sure if these may help, but thought I would throw them
out there.
Similar Messages
-
I am writing a piece of code that basically says if a certain MC reaches a ypos of -50 to perform a set of actions:
EXAMPLE CODE
if(balloon.clip.y <= topBounds)
//actions here
But for some reason it wasn't recognizing when the MC would reach the specified ypos. I did a simple trace statement of the stage height and width because I suspected something was off with the script reading x and y positions. And sure enough the output of the trace did not correctly match what my actual stage size was set to in my fla.
trace(stage.stageHeight); This traced 798
trace(stage.stageWidth); This traced 1440
While my actual stage is set to 550x400.
Am I missing something here? I also traced the ypos of the moving MC and the trace output positions that were nowhere near the actual y positions of the MC as it moved. Ironically though, the external class file to this object recognizes the correct x and y positions when I call the function from the .as file. Only when I try to call the function from the fla file do I run into this issue of incorrect x and y positions.
Any help? ThanksBelow is my code for my as class file and the code being called from the stage within the fla file. The issue I am having is with the conditional statement in the fla code, I have highlighted it in bold and italics. The ypos of the MC is not registering at -50 when clearly the object has a y position of -50. Something seems messed up with the x and y positions of the clip on the stage because the y position traced to teh output panel is nowhere close to the actual y position of the clip on the stage as it moves.
.as file code
package
import flash.display.Stage;
import flash.display.*;
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
public class Balloon
public var clip: MovieClip;
public var xVel: Number = 0;
public var yVel: Number = 0;
public var upwardForce: Number = 0; // applies to y value
public var shrink: Number = 1;
public var fade: Number = 0;
public var topBounds: Number = -50
public function Balloon(symbol:Class, target:DisplayObjectContainer, xpos:Number, ypos:Number, size:Number)
clip=new symbol();
target.addChild(clip);
clip.x = xpos;
clip.y = ypos;
clip.scaleX=clip.scaleY=size;
} // end Balloon constructor function
public function moveObject():void
clip.x += xVel;
clip.y += yVel;
yVel -= upwardForce;
clip.scaleX *= shrink;
clip.scaleY *= shrink;
clip.alpha -= fade;
}//end moveObject function
public function removeObject():void
clip.parent.removeChild(clip);
}// remove balloon from the stage
} // end Balloon class
}// end package
code inside fla
var balloonArray:Array = new Array();
stage.addEventListener(Event.ENTER_FRAME, startBalloons)
function startBalloons(evt:Event):void
var balloon: Balloon; // referencing our Balloon Class
for(var i:int=0; i<balloonArray.length; i++)
balloonArray[i].moveObject(); // calls moveObject function thats in the class file
balloon = new Balloon(hotAirBalloon, this, randomRange(200, 400), randomRange(400, 550), randomRange(0.3, 1));
balloon.xVel = -3;
balloon.yVel = -4;
balloon.shrink = 0.9999;
balloon.fade = 0.000011;
balloon.upwardForce = .005
balloonArray.push(balloon);
if(balloonArray.length>randomRange(1, 5))//creates only 3 balloons and removes all others created from th array
balloon.removeObject();
if(balloon.clip.y <= -50)
trace("balloon has reached the top"
var balloonTimer:Timer = new Timer(randomRange(25,45)*1000, 1);
balloonTimer.addEventListener(TimerEvent.TIMER,timerFinished);
balloonTimer.start();
function timerFinished(event:TimerEvent):void
trace("time's up")
balloonTimer.stop();
balloon.clip.x = Math.random() * (400-200) + 200; // give random x pos to start from
balloon.clip.y = Math.random() * (1000-400) + 400; // give random y pos to start from
balloon.clip.scaleX = balloon.clip.scaleY = Math.random() * (1-0.3) + 0.3;
balloon.clip.alpha=1;
} // end startBalloons function
function randomRange(offset:Number, maxValue:Number) // generic function for randomizing object properties
return Math.random() * (maxValue-offset) + offset -
I have a proc, in which i have a logic to remove child from the xml node. I have a xml_doc variable pointed to the xml document.
Sample xml to explain my issue better:
<?xml version="1.0" encoding="UTF-8"?>
<oa:stackLayout id="294641" controllerClass="oracle...." textTranslationExpansion="50%"......>
<ui:contents>
<oa:spacer id="_czn1-spacer1_294644" ..../>
<oa:tableLayout id="294645" adminCustomizable="false" width="100%" ....>
<ui:contents>
<oa:rowLayout id="294642" extends="/../../..TextFeature" .../>
<oa:rowLayout id="294643" extends="/../../../IntegerInputWithRangeDisplay" .../>
</ui:contents>
</oa:tableLayout>
</ui:contents>
</oa:stackLayout>
/****************************Code Start************************/
Proc dummy_proc(....)
-- open XML parser
Open_Parser();
l_xmldoc :=parse_JRAD_Document(p_doc_full_name => l_jrad_doc);
// l_xmldoc contains the xml docuement
l_parent_xml_node // Contains the2nd ui:contents node
l_child_xml_node // contains the oa:rowLayout for 294642
dbmsoutput stmts for printing l_xmldoc document - Before removing the node
l_out_xml_node:=xmldom.removeChild(l_parent_xml_node,l_child_xml_node);
dbmsoutput stmts for printing l_xmldoc document - After removing the node
end
/****************************Code End ************************/
Issue :
Scenario 1: When the above proc is called through OAF page submit button, the child node is not getting removed.
Scenario 2: When i run the proc by passing the same values using a anonymous block the child node is getting removed.
Any help is appreciated, why when running the flow the OAF page is stopping the child node to be removed is my question.
Let me know for any specific questions...How it can be Privilege issue, in both the scenarios same values are getting passed to the procedure. And how xmldom.removechild depends on user priveleges?
Edited by: 870314 on Jul 12, 2011 2:02 AM -
If a mod could delete my other post as I am quite far on from that and now having different issues. Thanks.
I am really stuck. I will try my best to explain things clearly. I am making an image gallery and I got the code from this gallery here.
http://www.flashmo.com/preview/flashmo_122_3d_curve_gallery
I made some changes to make it how I wanted it, nothing drastic though. So now I have a nice gallery.
Explaining what I am trying to do will better help explain things. I am creating a modelling agency website. The gallery I created above will display an individual image of every model in the agency (which it does). Now when one of the model images is clicked, I then need it to load another image gallery which contains the complete set of images for that model, plus some of their information etc.
The way I am approaching it at the moment is to create an individual image gallery for every model in its own fla file. If say the first model is clicked (image 1) it will load the corresponding swf (1.swf). I am not sure how good it is loading an swf into what I already have, but couldnt think of another way. So now I have a seperate image gallery just to test things out, and I need to load it into my original image gallery.
So, I will show the code for the first gallery (which displays the individual images of each model). The important methods are p_click (which hides the first gallery and loads the external swf), and on_pic_loaded (which displays the external swf).
I hope you understand what I am attempting, as I dont know if I have explained it right as my brain is going dead! (although I am liking the challenge).
import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.materials.*;
import caurina.transitions.*;
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
var container_x:Number = stage.stageWidth * 0.5;
var container_y:Number = stage.stageHeight * 0.5 + 160;
var container:Sprite = new Sprite();
container.x = container_x;
container.y = container_y;
addChild(container);
var scene:Scene3D = new MovieScene3D(container);
var cam:Camera3D = new Camera3D();
cam.zoom = 6;
tn_url_target.visible = false;
tn_title.text = "";
tn_desc.text = "";
tn_url.text = "";
loading_info.text = "";
url_button.visible = false;
var no_of_ring:Number = 1;
var angle:Number = 0;
var p_dict:Dictionary = new Dictionary();
var pa:Array = new Array();
var filename_list = new Array();
var url_list = new Array();
var url_target_list:Array = new Array();
var title_list = new Array();
var description_list = new Array();
var folder:String = "photos/thumbs/";
var i:Number;
var total:Number;
var flashmo_xml:XML = new XML();
var pic_loader:Loader = new Loader();
var mLoader:Loader = new Loader();
var xml_loader:URLLoader = new URLLoader();
xml_loader.load(new URLRequest("thumbnail_list_5.xml"));
xml_loader.addEventListener(Event.COMPLETE, create_thumbnail);
function create_thumbnail(e:Event):void
flashmo_xml = XML(e.target.data);
total = flashmo_xml.thumbnail.length();
var angle_per:Number = Math.PI * 2 * no_of_ring / total;
for( i = 0; i < total; i++ )
filename_list.push( flashmo_xml.thumbnail[i][email protected]() );
url_list.push( flashmo_xml.thumbnail[i][email protected]() );
url_target_list.push( flashmo_xml.thumbnail[i][email protected]() );
title_list.push( flashmo_xml.thumbnail[i][email protected]() );
description_list.push( flashmo_xml.thumbnail[i][email protected]() );
var bfm:BitmapFileMaterial = new BitmapFileMaterial(
folder + flashmo_xml.thumbnail[i][email protected]());
bfm.oneSide = false;
bfm.smooth = true;
var p:Plane = new Plane(bfm, 100, 100, 2, 2);
scene.addChild(p);
var p_container:Sprite = p.container;
p_container.name = "flashmo_" + i;
p_dict[p_container] = p;
p_container.buttonMode = true;
p_container.addEventListener( MouseEvent.ROLL_OVER, p_rollover );
p_container.addEventListener( MouseEvent.ROLL_OUT, p_rollout );
p_container.addEventListener( MouseEvent.CLICK, p_click );
p.rotationY = - (i * angle_per) * (180/Math.PI) + 90;
p.x = Math.cos(i * angle_per) * 300;
p.z = Math.sin(i * angle_per) * 300;
p.y = Math.floor( i / 22 ) * 5;
function startLoad()
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest("/subgallery/1.swf");
mLoader.load(mRequest);
function p_rollover(me:MouseEvent)
var sp:Sprite = me.target as Sprite;
Tweener.addTween( sp, {alpha: 0.5, time: 0.5, transition:"easeOutExpo"} );
function p_rollout(me:MouseEvent)
var sp:Sprite = me.target as Sprite;
Tweener.addTween( sp, {alpha: 1, time: 0.4, transition:"easeInExpo"} );
function p_click(me:MouseEvent)
var sp:Sprite = me.target as Sprite;
var s_no:Number = parseInt(sp.name.slice(8,10));
var mRequest:URLRequest = new URLRequest("subgallery/1.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, on_pic_loaded);
mLoader.load(mRequest);
Tweener.addTween( container, { y: 1200, time: 0.6, transition:"easeInExpo" } );
function goto_URL(me:MouseEvent)
navigateToURL(new URLRequest(tn_url.text), tn_url_target.text);
function on_open(e:Event):void
loading_info.text = "Loading... 0%";
function on_progress(e:ProgressEvent):void
var percent:Number = Math.round(e.bytesLoaded / e.bytesTotal * 100);
loading_info.text = "Loading... " + percent + "%";
function on_pic_loaded(e:Event):void
addChild(e.currentTarget.content);
//addChildAt(mLoader, 1);
mLoader.x = Math.round(stage.stageWidth - mLoader.width) * 0.5;
mLoader.y = Math.round(stage.stageHeight - mLoader.height) * 0.5;
//mLoader.addEventListener(MouseEvent.CLICK, remove_pic);
Tweener.addTween( mLoader, { alpha: 1, time: 0.8, transition:"easeInExpo" } );
removeEventListener(Event.ENTER_FRAME, render);
function remove_pic(e:Event):void
Tweener.addTween( pic_loader, { alpha: 0, time: 1, onComplete:function() { removeChild(this); } } );
Tweener.addTween( container, { y: container_y, time: 1, delay: 1, transition:"easeOutExpo"} );
addEventListener(Event.ENTER_FRAME, render);
tn_title.text = "";
tn_desc.text = "";
tn_url.text = "";
url_button.visible = false;
addEventListener(Event.ENTER_FRAME, render);
function render(e:Event):void
var distance_x:Number = (stage.mouseX - 400) * 0.0001;
angle += distance_x;
cam.x = - Math.cos(angle) * 150;
cam.z = Math.sin(angle) * 150;
scene.renderCamera(cam);
Current issues as the moment is firstly, I dont know if this is the best way to achieve what I want. Maybe there is a better option someone could tell me about, but you have to remember that each image displayed here will have multiple images to go with it.
In terms of what I am attempting above, I currently get
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///C|/Users/Nick/Desktop/gallery/gallery.xml
at _1_fla::MainTimeline/frame1()
I assume its a url error so I changed all urls in both fla's to contain the whole url path. Didnt seem to work though unless I missed something.
Any advise on absolutely anything will be so appreciated.
Many thanks
NickSorry about that. If you can check my history, I normally always thank people who have helped, and I was intending to go back on the last few to sort them out. Just got my first job so it has been rather hectic and been stressing out to much. Also, I do things slightly different to other people. If I receive a correct answer (which I normally do thank), I tend not to actually reply but to thank instead, mainly because if I reply I am pushing unanswered questions further down the list and eventually out of view. I will go back and sort out the thanks I owe.
In terms of asking the mods, other forums I visit are normally moderated by the community, so I assumed that someone like yourself might be the moderator.
I tottally understand what you are saying, and as I say, I am normally on top of this. Will go back now and sort out the thanks.
Sorry for the delay.
Nick -
Hi,
I am trying to implement a simple image gallery with alpha transition using as3. But an issue is occuring with this. After each image alpha transition, the stage becomes blank. The code i have used for image Gallery is following.CAn anybody help me. I am trying this for a week. but still i have a hope for make this working. So please help me.
import flash.display.Loader;
import flash.display.*;
import gs.TweenLite;
const TIMER_DELAY = 2000;
var totImages:Number;
var index:Number = 0;
var imgArr:Array = new Array();
var currentContainer:MovieClip = holder0;
currentContainer.alpha = 0;
var transTimer:Timer = new Timer(TIMER_DELAY);
//transTimer.addEventListener(TimerEvent.TIMER, startTransition);
var imgLoader:Loader = new Loader();
var myXML:XML = new XML();
var XML_URL:String = "images.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(event:Event):void{
myXML = XML(myLoader.data);
processXML(myXML);
function processXML(xml){
totImages = xml.children().length();
for(var i=0;i<totImages;i++){
var tempVar = xml..item[i]..image;
imgArr.push(tempVar);
//transTimer.start();
currentContainer = holder0;
loadImage();
function loadImage(){
var url = imgArr[index];
//ImgLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressStatus);
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, fadeInImg);
var fileRequest:URLRequest = new URLRequest(url);
imgLoader.load(fileRequest);
currentContainer.addChild(imgLoader);
function fadeInImg(e:Event){
TweenLite.to(currentContainer,3,{alpha:1,delay:2,onComplete:switchClip});
function switchClip(){
if(index < totImages){
index++;
} else {
index = 0;
if(currentContainer == holder0){
currentContainer = holder1;
} else {
currentContainer = holder0;
currentContainer.alpha = 0;
MovieClip(this.root).swapChildren(holder0, holder1);
loadImage();
Thanks and Regards,
SreelashHi Adrei, I have implemented the thumbnail button also. Its working but the problem is that thumbnail buttons and controls are placing behind the image container. How can i place the thumbnail buttons and control buttons over the image. You can view the result in the following url:
http://www.creative-showcase.co.uk/BirdStudiosOld/Videos/test/scrllGallAnd.html
The working swf is with the following url:
http://www.creative-showcase.co.uk/BirdStudiosOld/Videos/test/scrllGall.html
The code that i used for creating thumbnail is following
import flash.display.DisplayObject;
import flash.display.*;
import flash.display.Loader;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.text.*;
import flash.net.*;
import flash.utils.Timer;
import gs.TweenLite;
import gs.easing.*;
var xmlURL:String = "http://www.creative-showcase.co.uk/BirdStudiosOld/Videos/test1/images.xml";
var loadedImages:Array = [];
var imageURLs:Array = [];
var thumbArr:Array = [];
var imageLoader:Loader;
var prevImage:DisplayObject;
var currentImage:DisplayObject;
var thumbContainer:MovieClip;
var currThumb:MovieClip;
var prevThumb:MovieClip = null;
var showTimer:Timer;
var timerDuration:int = 5000;
var tweenDuration:int = 2;
var currentIndex:int = 0;
var activIndx:Number = 0;
var slidesHolder:Sprite;
var prvFlag:Boolean = false;
var nxtFlag:Boolean = false;
var twnFlag:Boolean = false;
var rt_lt_Flag:Boolean = true;
var myXMLURL:URLRequest = new URLRequest(xmlURL);
var xmlLoader:URLLoader = new URLLoader(myXMLURL);
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
xmlLoader.load(myXMLURL);
var a:int = 90;
ctrlBox.btnPlay.buttonMode = true;
ctrlBox.nextImg.buttonMode = true;
ctrlBox.prevBtn.buttonMode = true;
ctrlBox.btnPause.buttonMode = true;
ctrlBox.btnPlay.visible = false;
ctrlBox.btnPause.addEventListener(MouseEvent.CLICK,stopScroll);
ctrlBox.btnPlay.addEventListener(MouseEvent.CLICK,startScroll);
ctrlBox.nextImg.addEventListener(MouseEvent.CLICK,shwNext);
ctrlBox.prevBtn.addEventListener(MouseEvent.CLICK,shwPrev);
function xmlLoaded(e:Event):void {
var a:int = 45;
e.target.removeEventListener(Event.COMPLETE, xmlLoaded);
processXML(XML(e.target.data));
function processXML(xml:XML):void {
var len:int = xml.children().length();
var tempVar:String;
for (var i:int = 0; i < len; i++) {
tempVar = "http://www.creative-showcase.co.uk/BirdStudiosOld/Videos/test1/" + xml..item[i]..image;
//trace(tempVar)
imageURLs.push(tempVar);
preload();
createThumbs();
function createThumbs():void{
thumbContainer = new MovieClip();
addChild(thumbContainer);
for(var i:int=0;i<9;i++){
var thmbHolder:MovieClip = new MovieClip();
thumbContainer.addChild(thmbHolder);
//MovieClip(this.root).swapChildren(currentImage, ctrlBox);
thmbHolder.buttonMode = true;
var thmb:thumbClass = new thumbClass();
thmbHolder.addChild(thmb);
thumbArr.push(thmbHolder);
thmbHolder.name = i.toString();
thmb.imgNum.text = (i+1).toString();
thmbHolder.addEventListener(MouseEvent.CLICK,showImage)
//trace(thmb.imgNum.text)
thmbHolder.x = i*(thmbHolder.width+5)+5;
thumbContainer.y = stage.stageHeight - thumbContainer.height;
function showImage(e:MouseEvent):void{
var imgIndx:Number = e.target.parent.parent.name;
prevThumb = currThumb;
currThumb = e.target.parent.parent;
currThumb.buttonMode = false;
if(activIndx != imgIndx){
prevThumb.buttonMode = true;
currentIndex = imgIndx-1;
shwNext(null);
activIndx = imgIndx;
} else {
stopScroll(null);
function preload():void{
var len:int = imageURLs.length;
for (var i:int = 0; i < len; i++) {
imageLoader = new Loader();
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onPreloadComplete);
loadedImages.push(imageLoader);
imageLoader.load(new URLRequest(imageURLs[i]));
function onPreloadComplete(e:Event):void {
e.target.removeEventListener(Event.COMPLETE, onPreloadComplete);
if (!showTimer && loadedImages[0].content && loadedImages[1].content ) startShow();
function startShow():void{
currentImage = loadedImages[0];
currentImage.alpha = 0;
slidesHolder = new Sprite();
var slideMask:Sprite = new Sprite();
var gr:Graphics = slideMask.graphics;
gr.beginFill(0xff0000);
gr.drawRect(0, 0, currentImage.width, currentImage.height);
gr.endFill();
addChild(slidesHolder);
addChild(slideMask);
slidesHolder.x = slideMask.x = 0;
slidesHolder.y = slideMask.y = 0;
slidesHolder.mask = slideMask;
slidesHolder.addChild(currentImage);
TweenLite.to(currentImage, 10, { alpha: 1 } );
showTimer = new Timer(timerDuration);
showTimer.addEventListener(TimerEvent.TIMER, slideTransition);
showTimer.start();
function slideTransition(e:TimerEvent):void{
var nextImage:int;
if(rt_lt_Flag == true){
if(nxtFlag == true){
showTimer.stop();
nxtFlag = false;
nextImage = currentIndex < loadedImages.length - 1 ? currentIndex + 1 : 0;
if (loadedImages[nextImage].content) {
currentIndex = nextImage;
loadedImages[currentIndex].x = slidesHolder.width;
slidesHolder.addChildAt(loadedImages[currentIndex], slidesHolder.getChildIndex(currentImage));
prevImage = currentImage;
currentImage = loadedImages[currentIndex];
showCurrent();
} else {
if(prvFlag == true){
showTimer.stop();
prvFlag = false;
nextImage = currentIndex > 0 ? currentIndex - 1 : loadedImages.length - 1;
if (loadedImages[nextImage].content) {
currentIndex = nextImage;
loadedImages[currentIndex].x = -(stage.stageWidth);
slidesHolder.addChildAt(loadedImages[currentIndex], slidesHolder.getChildIndex(currentImage));
prevImage = currentImage;
currentImage = loadedImages[currentIndex];
showCurrent();
activIndx = currentIndex;
//trace(currentIndex)
function showCurrent():void{
// make sure they have proper alphas
//prevImage.alpha = 1;
//currentImage.alpha = 0;
//TweenLite.to(prevImage, tweenDuration, { x: -slidesHolder.width } );
twnFlag = true;
if(rt_lt_Flag == true){
TweenLite.to(currentImage, tweenDuration, { x: 0, onUpdate:onTweenProgress, onComplete: removePrevious } );
} else {
TweenLite.to(currentImage, tweenDuration, { x: 0, onUpdate:onTweenProgress, onComplete: removePrevious } );
function onTweenProgress():void{
if(rt_lt_Flag == true){
prevImage.x = currentImage.x - prevImage.width;
} else {
prevImage.x = currentImage.x + prevImage.width;
function removePrevious():void {
if (slidesHolder.contains(prevImage)) slidesHolder.removeChild(prevImage);
twnFlag = false;
function stopScroll(e:MouseEvent):void{
ctrlBox.btnPlay.visible = true;
ctrlBox.btnPause.visible = false;
showTimer.stop();
function startScroll(e:MouseEvent):void{
rt_lt_Flag = true;
ctrlBox.btnPlay.visible = false;
ctrlBox.btnPause.visible = true;
resetListener(timerDuration=5000,tweenDuration=2)
function shwNext(e:MouseEvent):void{
if(twnFlag == false){
rt_lt_Flag = true;
stopScroll(null);
nxtFlag = true;
resetListener(timerDuration=0,tweenDuration=1)
function shwPrev(e:MouseEvent):void{
if(twnFlag == false){
rt_lt_Flag = false;
stopScroll(null);
prvFlag = true;
resetListener(timerDuration=0,tweenDuration=1)
function resetListener(timerDuration,tweenDuration){
showTimer.removeEventListener(TimerEvent.TIMER, slideTransition);
showTimer = new Timer(timerDuration);
showTimer.addEventListener(TimerEvent.TIMER, slideTransition);
showTimer.start();
Can you help me on how can i swap the depth of images and control buttons.
Thanks and regards,
Sreelash -
Hello, I'm making a game in which I have some drag and drop items that they can be multiplied as many as you want. This items have to stay in the scene and I also have a bin in the menu where If you drag them they have to disappear.The problem is that I tried with multiple coordinates and they disappear also in the scene in the moment that I'm dragging them out of the menu. So, my question is:What could be wrong? Is the issue in the code?
Thank you for taking the time to help me. It's my first game in AS3 so I'm not so familiar with the codes.
import flash.display.Sprite;
import flash.events.MouseEvent;
DDB1.addEventListener(MouseEvent.MOUSE_DOWN, createDDB1);
var _DDB1:Sprite;
function createDDB1(evt:MouseEvent){
_DDB1 = new DDB1MC();
_DDB1.x = evt.stageX;
_DDB1.y = evt.stageY;
_DDB1.rotation = evt.currentTarget.rotation;
_DDB1.transform.colorTransform = evt.currentTarget.transform.colorTransform
addChild(_DDB1);
_DDB1.startDrag(false);
_DDB1.addEventListener(MouseEvent.MOUSE_DOWN, dragDDB1);
stage.addEventListener(MouseEvent.MOUSE_UP, dropDDB1);
function dragDDB1(evt:MouseEvent){
evt.stopPropagation();
_DDB1 = evt.currentTarget as Sprite;
_DDB1.startDrag(false);
stage.addEventListener(MouseEvent.MOUSE_UP, dropDDB1);
function dropDDB1(e:MouseEvent):void {
_DDB1.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP,dropDDB1);
if (_DDB1.x>700 || _DDB1.x < 755 || _DDB1.y < 240 || _DDB1.y > 155) {
_DDB1.removeEventListener(MouseEvent.MOUSE_DOWN, dragDDB1);
_DDB1.parent.removeChild(_DDB1);
_DDB1 = null;Chances are that the problem lies in the following line:
if (_DDB1.x>700 || _DDB1.x < 755 || _DDB1.y < 240 || _DDB1.y > 155) {
That line essentially says if(the object is anywhere) due to using the OR ( || ) operator. If any one of those things is true then the condition is satisfied, which becxause they overlap will always be true for at least two of them. If that is supposed to be restricting the object to within an area you likely want to all of those conditions to be satsified. So in that case you need to use the AND operator ( && ). -
any idea why removeChild(splash_mc); is taking btnSet with it?
package
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.media.*;
import utils.Utils;
import gs.*;
import gs.easing.*;
import nav.*;
import flash.text.*;
import buttonSet.ButtonSet;
import preload.LinePreloader;
public class GoldClubMain extends MovieClip
private var btnSet:ButtonSet;
public var navModel:NavigationModel;
public var navView:NavigationView;
public var navController:NavigationController;
private var pre:LinePreloader;
//SOUND
// public var sound:mainBeat = new mainBeat();
// public var channel:SoundChannel;
// public var soundOn:SoundTransform = new SoundTransform(1, .5);
// public var soundOff:SoundTransform = new SoundTransform(0, .5);
public function GoldClubMain()
navView = new NavigationView(container_mc);
navModel = new NavigationModel()
navController = new NavigationController(navModel);
navView.model = navModel;
splash_mc.buttonMode = true;
splash_mc.addEventListener(MouseEvent.CLICK, enterSite);
btnSet = new ButtonSet()
btnSet.addButtons([homeBtn_mc, danceBtn_mc, partyBtn_mc, dineBtn_mc, featBtn_mc, calBtn_mc]);
navController.addCustomButton([homeBtn_mc, danceBtn_mc, partyBtn_mc, dineBtn_mc, featBtn_mc, calBtn_mc]);
addChild(btnSet)
btnSet.alpha = 0;
private function enterSite(event:MouseEvent):void
TweenLite.to(splash_mc, .5, {alpha:0});
TweenLite.to(tMaskL_mc, .5, {delay:.5, x:-133, ease:Strong.easeOut});
TweenLite.to(tMaskR_mc, .5, {delay:.5, x:627, ease:Strong.easeOut, onComplete:removeSplash});
private function removeSplash():void
TweenLite.to(tMaskL_mc, .5, {delay:.2, x:-400, ease:Strong.easeOut});
TweenLite.to(tMaskR_mc, .5, {delay:.2, x:900, ease:Strong.easeOut});
TweenLite.to(btnSet, .5, {delay:.8, alpha:1, onComplete:addPage});
private function addPage():void
removeChild(splash_mc);
navModel.load(new URLRequest("xml/Main.xml"));
Thanks!no, there are differences. but i don't know how any would be related to your issue.
but if removing one object seems to remove another additional object, you should check if that additional object is a child of the explicitly removed one. -
Stack Lag, Simultaneous addChild/addtoState Issues
It would be great if someone could help explain a few issues
I have been having:
- The main issue I have been dealing with is a lag time
between addChild/removeChild and the load of the Images, and the
actual finished load of the images (complete with height and
width). Is there a hack that properly checks and halts all other
code until the action is off the stack?
For my particular application, when I check if the object
exists as a child admist addChild/removeChild calls, sometimes it
is and sometimes its not. I'm currently using a hack to make sure
the height and width values are loaded, but I don't know enough
about the internal architecture to write a hack for
addChild/removeChild calls on the stack.
- Is there a function that checks if an object exists as a
child without throwing an error if it is not? It seems everything
that getChildIndex, etc will throw runtime errors if it is not a
child. While it may be a workaround to catch the errors, it still
doesn't return the existence of the object as a child.
- Is there a way to simultaneously add a child to a specific
position to an displayobject and a mxml defined state?
Thanks! -
DrawViewPortToBitmapData issue on AIR 13.0.0.42
fixed on AIR 3.8 for IOS
https://bugbase.adobe.com/index.cfm?event=bug&id=3161013
Adobe AIR 3.8 relase notes, notable bug fixes:
StageWebView.drawViewPortToBitmapData draws incorrect bitmap on retina devices(3558603)
But this is still an issue on AIR 13.0.0.42 at Galaxy S3 (Android 4.3)
How to solve this problem?
There is an example test file (.fla) at zip: Link
here is the code:
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.MouseEvent
import flash.geom.Rectangle;
import flash.media.StageWebView;
var webView:StageWebView = new StageWebView();
webView.viewPort = new Rectangle(0,0,stage.stageWidth,stage.stageHeight-100);
webView.stage = this.stage;
webView.loadURL("http://labs.adobe.com/");
var webViewBitmap:Bitmap;
addBitmap.addEventListener(MouseEvent.CLICK, addBitmapClickHandler);
removeBitmap.addEventListener(MouseEvent.CLICK, removeBitmapClickHandler);
function addBitmapClickHandler(event:MouseEvent):void
var rect:Rectangle = webView.viewPort;
var bitmapData:BitmapData = new BitmapData(rect.width,rect.height,true,0xff0000);
webView.drawViewPortToBitmapData(bitmapData);
webViewBitmap = new Bitmap(bitmapData);
webView.stage = null;
addChild(webViewBitmap);
function removeBitmapClickHandler(event:MouseEvent):void
if (contains(webViewBitmap))
removeChild(webViewBitmap);
webView.stage = this.stage;Thanks for reporting the issue, could you please try putting in “NO_SCALE” in your code as following?
stage.scaleMode = StageScaleMode.NO_SCALE;
Regards,
Jitender
Adobe AIR Team -
Hi,
I am using Flex Grid in my project where i am successfully able to populate xml data dynamically. what i am doing here, I am dynamically generating the xml using httpservice. This HttpService is returning an XmlList that i am using to bind the grid dynamically.
Here i am not fixing the column header text and column width as in future the number of cloumns can be increased so i can't fix the column header text and column width.
Here the issue is: how to remove " _x0020_" from the header text and how to fix column width dynamically using Action Script.
For better idea please refer the screen shot as attached along with post.
Please have a look on the code as pasted below:
<?xml version="1.0" encoding="utf-8"?><mx:Canvas
xmlns:mx="http://www.adobe.com/2006/mxml" width="862" height="580"><mx:TitleWindow
x="182" y="113" width="670" height="395" layout="vertical" title="
Top Presenters" fontSize="12"horizontalAlign="
center" verticalAlign="top" showCloseButton="true" close="CloseGridWindow()" verticalScrollPolicy="
off" borderColor="#000000"horizontalScrollPolicy="
off" borderThicknessLeft="3"borderThicknessRight="
3" borderThicknessBottom="3" creationComplete="GetTopPresentersXMLData()" backgroundColor="
#FFFFFF" cornerRadius="
0" color="#FFFFFF" >
<mx:Script><![CDATA[
import mx.controls.dataGridClasses.DataGridColumn;
import mx.collections.XMLListCollection;
import mx.managers.PopUpManager;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
import mx.events.FlexEvent;
import mx.controls.Alert;
//funtion to get Top Presenters xml data
private function GetTopPresentersXMLData():void{
var httpService:HTTPService = new HTTPService();httpService.url =
"http://ri/CItSL/Ters.aspx?mode=all&month=march&year=2009";httpService.resultFormat =
"e4x";httpService.addEventListener(ResultEvent.RESULT, onResultHttpService);
httpService.send();
Bindable]
private var _xmlData:XMLList;
//funtion to receive Http Service Response as XML Document
private function onResultHttpService(e:ResultEvent):void{
var xmlData:XMLList = e.result.Table;myGrid.dataProvider = xmlData;
for each (var node:XML in xmlData[0].children()){
addDataGridColumn(node.name());
//function to add column dynamically
private function addDataGridColumn(dataField:String):void{
//var spacePattern:RegExp=/_x0020_/g;
//var andPattern:RegExp=/_x0026_/g;
//dataField=dataField.replace(spacePattern," ");
//dataField=dataField.replace(andPattern,"&");
var dgc:DataGridColumn=new DataGridColumn(dataField);
var cols:Array=myGrid.columns;cols.push(dgc);
myGrid.columns=cols;
myGrid.validateNow();
//funtion to remove grid window
private function CloseGridWindow():void{
PopUpManager.removePopUp(
this);}
]]>
</mx:Script>
<mx:DataGrid id="myGrid" alternatingItemColors="[#A2F4EF, #EFDE7D]" x="0" y="0" sortableColumns="false" width="658" height="352" fontSize="10" verticalAlign="middle" editable="false" enabled="true" horizontalGridLineColor="#befcc4" color="#000000">
</mx:DataGrid>
</mx:TitleWindow>
Please let me know, If anyone knows the solution.Hi,
You can follow the below mentioned code and see if this works for you.
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="onComplete();">
<mx:Script>
<![CDATA[
// imports:
import mx.events.FlexEvent;
import mx.core.UIComponent;
import mx.controls.dataGridClasses.DataGridColumn;
import mx.controls.Text;
import mx.utils.ObjectUtil;
import mx.controls.Label;
import mx.collections.ArrayCollection;
// data provider:
[Bindable] private var dp:ArrayCollection = new ArrayCollection();
private function onComplete():void {
// populate data provider here
// to avoid calcMaxLengths execution when the app is created:
dp = new ArrayCollection(
{ col1: "Short", col2: "Other column 1" },
{ col1: "Some long string", col2: "Other column 2" },
{ col1: "Short", col2: "Other column 3" },
{ col1: "Short", col2: "Other column 4" },
{ col1: "The longest value in this column", col2: "Other column 5" },
{ col1: "Short", col2: "Other column 6" },
{ col1: "Short", col2: "Other column 7" }
// this is going to be executed whenever the data provider changes:
[Bindable("dataChange")]
private function calcMaxLengths(input:ArrayCollection):ArrayCollection {
// if there are items in the DP:
if ( input.length > 0 ) {
// and no SPECIAL child exists:
if ( getChildByName("$someTempUICToRemoveAfterFinished") == null ) {
// create new SPECIAL child
// this is required to call measureText
// if you use custom data grid item renderer
// then create instance of it instead of UIComponent:
var uic:UIComponent = new UIComponent();
// do not show and do not mess with the sizes:
uic.includeInLayout = false;
uic.visible = false;
// name it to leverage get getChildByName method:
uic.name = "$someTempUICToRemoveAfterFinished";
// add event listener:
uic.addEventListener(FlexEvent.CREATION_COMPLETE, onTempUICCreated);
// add to parent:
addChild(uic);
// return an input:
return input;
// called when SPECIAL child is created:
private function onTempUICCreated(event:FlexEvent):void {
// keep the ref to the SPECIAL child:
var renderer:UIComponent = UIComponent(event.target);
// output - this will contain max size for each column:
var maxLengths:Object = {};
// temp variables:
var key:String = "";
var i:int=0;
// for each item in the DP:
for ( i=0; i<dp.length; i++ ) {
var o:Object = dp.getItemAt(i);
// for each key in the DP row:
for ( key in o ) {
// if the output doesn't have current key yet create it and set to 0:
if ( !maxLengths.hasOwnProperty(key) ) {
maxLengths[key] = 0;
// check if it's simple object (may cause unexpected issues for Boolean):
if ( ObjectUtil.isSimple(o[key]) ) {
// measure the text:
var cellMetrics:TextLineMetrics = renderer.measureText(o[key]+"");
// and if the width is greater than longest found up to now:
if ( cellMetrics.width > maxLengths[key] ) {
// set it as the longest one:
maxLengths[key] = cellMetrics.width;
// apply column sizes:
for ( key in maxLengths ) {
for ( i=0; i<dg.columnCount; i++ ) {
// if the column actually exists:
if ( DataGridColumn(dg.columns[i]).dataField == key ) {
// set size + some constant margin
DataGridColumn(dg.columns[i]).width = Number(maxLengths[key]) + 12;
// cleanup:
removeChild(getChildByName("$someTempUICToRemoveAfterFinished"));
]]>
</mx:Script>
<mx:DataGrid id="dg" horizontalScrollPolicy="on" dataProvider="{calcMaxLengths(dp)}" width="400">
<mx:columns>
<mx:DataGridColumn dataField="col1" width="40" />
<mx:DataGridColumn dataField="col2" width="100" />
</mx:columns>
</mx:DataGrid>
</mx:WindowedApplication>
Regards -
Air for Android 4.0 cacheAsBitmap Issue
Problem Description:
The frame rate of my app drops dramatically if I use:
cacheAsBitmapMatrix or cacheAsBitmap
or if I add a child of a sprite instance which are already cached are added to the displayList.
This behavior only takes place in Android 4.0 GALAXY NEXUS
The App runs on slower devices: Galaxy 2S Android 2.3 and iPhone 4 super smooth (iOS 5)
Is this a known issue with the new operation system ICS 4.0Unfortunatelly I didn´t get any answer from Adobe so I don´t know if this is a bug or a feature!
Here is my workaround code! In my case that works just perfect. Of course if I want to do any transitions to my button I have to do it with matrixes and not only with width or height property.
private function myCacheAsBitmap() : void
if ( bttnWidth > 0 && bttnHeight > 0 )
buttonBitmapData = new BitmapData ( bttnWidth, bttnHeight, true, 0x00000000 );
buttonBitmap = new Bitmap ( buttonBitmapData );
var scaleMatrix : Matrix;
scaleMatrix = new Matrix (1, 0, 0, 1, 0, 0);
buttonBitmapData.draw ( this, scaleMatrix, null, null, null, true);
addChild ( buttonBitmap );
removeChild ( offStateBackground );
removeChild ( onStateBackground );
removeChild ( buttonText );
if ( pictureLoaded == true)
removeChild ( iconBitmap ); -
Big gravity issue, need much help please.
Hey there, so my game is a platformer. I have gravity working fine, but the only issue is, is that when I just and land on the ground my character goes through the ground a little and if the platform is thin enough, or Im falling fast enough, I go right through the platform, with obviousness, this is a huge problem, but I cannot solve the problem, even when I set the gravity to 0 once the floor is hit.
Who ever wants to help I am going to place the 3 as files that associate with the ground and the gravity, along with the hit testings below.
MAIN FILE
package
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.events.KeyboardEvent;
import flash.ui.*;
import flash.utils.*;
import flash.geom.*;
import flash.net.*;
import flash.media.Sound;
import flash.media.SoundTransform;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Main extends Sprite
var Hero = new Character();
var platforms = new Platforms();
var BackGround = new Background();
var Keys1 = new Keys();
var nDir:int;
var nDirUpDown:int;
var tmrHitTest:Timer = new Timer(35);
var tmrCurrentStage:Timer = new Timer(35);
var kYmove:int=150;
var kXmove:int=400;
var i:int=0;
public function Main()
addChild(BackGround);
addChild(Hero);
addChild(platforms);
addChild(Keys1);
BackGround.y+=kYmove;
BackGround.x+=kXmove;
Hero.y+=kYmove;
Hero.x+=kXmove;
platforms.y+=kYmove;
platforms.x+=kXmove;
Keys1.y+=kYmove;
Keys1.x+=kXmove;
//Checks if the left key has been released;
stage.addEventListener(KeyboardEvent.KEY_UP,keyUpHandlerLeft);
//Checks if the right key has been released;
stage.addEventListener(KeyboardEvent.KEY_UP,keyUpHandlerRight);
stage.addEventListener(KeyboardEvent.KEY_DOWN,mover);
stage.addEventListener(KeyboardEvent.KEY_DOWN,moverUpDown);
stage.addEventListener(MouseEvent.CLICK,Clicking);
tmrHitTest.addEventListener("timer",timerHitTest);
tmrHitTest.start();
tmrCurrentStage.addEventListener("timer",timerCurrentStage);
tmrCurrentStage.start();
// constructor code
public function Clicking(e:MouseEvent):void
platforms.bClicked = true;
//trace(mouseX);
//trace(mouseY);
public function mover(event:KeyboardEvent)
nDir = event.keyCode;
if (nDir==37||nDir==37&&nDirUpDown==32)
{// left
Hero.bLeftKeyDown = true;
else if (nDir==39||nDir==39&&nDirUpDown==32)
{// right
Hero.bRightKeyDown = true;
function timerCurrentStage(eventArgs:TimerEvent)
if (platforms.LevelOne.CurrentStage == platforms.LevelOne.iStage)
if(platforms.LevelOne.bRemoveStage == true)
while(platforms.LevelOne.arFloor.length > 0){
platforms.LevelOne.removeChild(platforms.LevelOne.arFloor.p op());
Hero.StandRight.x=-320;
Hero.StandRight.y=400;
//platforms.LevelOne.arFloor.length = 0;
platforms.LevelOne.bRemoveStage = false;
if(platforms.LevelOne.CurrentStage == 1){
}else if(platforms.LevelOne.CurrentStage == 2){
platforms.LevelOne.GenerateLevel2();
}else if(platforms.LevelOne.CurrentStage == 3){
platforms.LevelOne.GenerateLevel3();
}else if(platforms.LevelOne.CurrentStage == 4){
platforms.LevelOne.GenerateLevel4();
}else if(platforms.LevelOne.CurrentStage == 5){
platforms.LevelOne.GenerateLevel5();
}else if(platforms.LevelOne.CurrentStage == 6){
platforms.LevelOne.GenerateLevel6();
}else if(platforms.LevelOne.CurrentStage == 7){
platforms.LevelOne.GenerateLevel7();
}else if(platforms.LevelOne.CurrentStage == 8){
platforms.LevelOne.GenerateLevel8();
}else if(platforms.LevelOne.CurrentStage == 9){
platforms.LevelOne.GenerateLevel9();
}else{
platforms.LevelOne.GenerateLevel10();
function timerHitTest(eventArgs:TimerEvent)
if(Hero.StandRight.hitTestObject(Keys1.key1)){
//if(bKeyFound==true){
//Keys1.removeChild(Keys1.key1);
//platforms.LevelOne.removeChild(platforms.LevelOne.arFloor[8]);
//bKeyFound=false;
if (platforms.LevelOne.TouchingGround(Hero.HeroGroundTouch))
Hero.bTouchingGround = true;
Hero.vy = 0;
else if (platforms.LevelOne.TouchingRoof(Hero.HeroRoofTouch))
Hero.vy = 0;
Hero.StandRight.y += 4;
else
Hero.bTouchingGround = false;
if (platforms.LevelOne.TouchingLeft(Hero.HeroLeftTouch))
//Hero.bTouchingLeft = true;
//Hero.vx = 0;
//Hero.ax = 0;
else if (platforms.LevelOne.TouchingRight(Hero.HeroRightTouch))
//Hero.bTouchingRight = true;
//Hero.vx = 0;
//Hero.ax = 0;
}else{
Hero.bTouchingLeft = false;
Hero.bTouchingRight = false;
function keyUpHandlerLeft(event:KeyboardEvent)
if (event.keyCode == 37)
Hero.bLeftKeyDown = false;
function keyUpHandlerRight(event:KeyboardEvent)
if (event.keyCode == 39)
Hero.bRightKeyDown = false;
private function moverUpDown(event:KeyboardEvent)
nDirUpDown = event.keyCode;
if (nDirUpDown==32)
{// Jump
Hero.GroundSnapped = false;
if (Hero.bDownKeyDown == false)
if (Hero.bTouchingGround == true)
// trace("Jump");
Hero.aGravity=1;
Hero.vy = -20;
Hero.bTouchingGround = false;
function keyUpHandlerDown(event:KeyboardEvent)
if (event.keyCode == 40)
Hero.bDownKeyDown = false;
CHARACTER FILE/PHYSICS
package
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.events.KeyboardEvent;
import flash.ui.*;
import flash.utils.*;
import flash.geom.*;
import flash.net.*;
import flash.media.Sound;
import flash.media.SoundTransform;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Character extends Sprite
var tmrMove:Timer = new Timer(35);
var tmrCoordinateMaintain:Timer = new Timer(35);
var bLeftKeyDown:Boolean = false;
var bRightKeyDown:Boolean = false;
var bTouchingGround:Boolean = false;
var bTouchingLeft:Boolean = false;
var bTouchingRight:Boolean = false;
var bDownKeyDown:Boolean;
var StandLeft = new standLeft ;
var StandRight = new standRight ;
var jumpRight = new JumpRight ;
var jumpLeft = new JumpLeft ;
var RunRight = new runRight ;
var RunLeft = new runLeft ;
var HeroGroundTouch = new heroGroundTouch ;
var HeroRoofTouch = new HeroTouchRoof ;
var HeroRightTouch = new HeroTouchRight ;
var HeroLeftTouch = new HeroTouchLeft ;
var GroundSnap:int = 0;
var GroundSnapped:Boolean = false;
var i:int = 0;
var ax:int = 0;
var vx:int = 0;
var vy:int = 0;
var Stance:int = 2;
var maxVelocity:int = 18;
var minVelocity:int = -18;
var maxGravity:int = 20;
var minGravity:int = -20;
var aGravity:int = 1;
var HeroSize:Number = 1;
public function Character()
StandRight.x = -320;
StandRight.y = 400;
StandRight.scaleX = HeroSize;
StandRight.scaleY = HeroSize;
StandLeft.scaleX = HeroSize;
StandLeft.scaleY = HeroSize;
RunRight.scaleX = HeroSize;
RunRight.scaleY = HeroSize;
RunLeft.scaleX = HeroSize;
RunLeft.scaleY = HeroSize;
jumpLeft.scaleX = HeroSize;
jumpLeft.scaleY = HeroSize;
jumpRight.scaleX = HeroSize;
jumpRight.scaleY = HeroSize;
addChild(StandRight);
addChild(StandLeft);
addChild(RunRight);
addChild(RunLeft);
addChild(jumpLeft);
addChild(jumpRight);
addChild(HeroGroundTouch);
addChild(HeroRoofTouch);
addChild(HeroRightTouch);
addChild(HeroLeftTouch);
StandLeft.visible = false;
RunLeft.visible = false;
RunRight.visible = false;
jumpLeft.visible = false;
jumpRight.visible = false;
HeroGroundTouch.visible = false;
HeroRoofTouch.visible = false;
HeroLeftTouch.visible = false;
HeroRightTouch.visible = false;
// constructor code
tmrMove.addEventListener("timer",timerMove);
tmrMove.start();
tmrCoordinateMaintain.addEventListener("timer",timerCoordinateMaintain);
tmrCoordinateMaintain.start();
function timerMove(eventArgs:TimerEvent)
//trace(StandRight.y);
if (((bLeftKeyDown == true) && bRightKeyDown == true))
//if both are pressed then do nothing
else if ((bLeftKeyDown == true))
if ((bTouchingGround != false))
Stance = 1;
jumpRight.visible = false;
jumpLeft.visible = false;
StandRight.visible = false;
RunRight.visible = false;
StandLeft.visible = false;
RunLeft.visible = true;
ax = -1;
else
Stance = 1;
jumpRight.visible = false;
jumpLeft.visible = true;
StandRight.visible = false;
RunRight.visible = false;
StandLeft.visible = false;
RunLeft.visible = false;
ax = -1;
else if ((bRightKeyDown == true))
if ((bTouchingGround != false))
Stance = 2;
jumpRight.visible = false;
jumpLeft.visible = false;
StandRight.visible = false;
RunRight.visible = true;
StandLeft.visible = false;
RunLeft.visible = false;
ax = 1;
else
Stance = 1;
jumpRight.visible = true;
jumpLeft.visible = false;
StandRight.visible = false;
RunRight.visible = false;
StandLeft.visible = false;
RunLeft.visible = false;
ax = 1;
else
ax = 0;
if ((vx > 0))
{//slows down veloctiies when no keys are pressed
vx -= 1 / 3;
else if ((vx < 0))
{//returns velocities to zero when keys are released
vx += 1 / 3;
else
vx = 0;
if ((Stance == 1))
{//Left Stance
if ((bTouchingGround != false))
StandRight.visible = false;
RunRight.visible = false;
StandLeft.visible = true;
RunLeft.visible = false;
jumpLeft.visible = false;
jumpRight.visible = false;
else
StandRight.visible = false;
RunRight.visible = false;
StandLeft.visible = false;
RunLeft.visible = false;
jumpLeft.visible = true;
jumpRight.visible = false;
else if ((Stance == 2))
{//Right Stance
if ((bTouchingGround != false))
StandRight.visible = true;
RunRight.visible = false;
StandLeft.visible = false;
RunLeft.visible = false;
jumpLeft.visible = false;
jumpRight.visible = false;
else
StandRight.visible = false;
RunRight.visible = false;
StandLeft.visible = false;
RunLeft.visible = false;
jumpLeft.visible = false;
jumpRight.visible = true;
}//if velocity is a
if ((vx > maxVelocity))
vx = maxVelocity;//stop too high velocities
if ((vx < minVelocity))
vx = minVelocity;
if ((vy < minGravity))
vy = minGravity;
if ((vy > maxGravity))
vy = maxGravity;
vx += ax;
vy += aGravity;
if ((((vx < 0) && bTouchingLeft == false) || vx > 0 && bTouchingRight == false))
StandRight.x += vx / 2.2;
if (((bTouchingGround == false) && vy != 0))
StandRight.y += vy;
else
//aGravity=0;
vy = 0;
//aGravity=1;
//trace(StandRight.x);
//trace(vy+" is the Gravity");
function timerCoordinateMaintain(eventArgs:TimerEvent)
//trace( "HERO.X = "+StandRight.x + "HERO.Y =" + StandRight.y);
//trace( vy + " Velocity");
StandLeft.x = StandRight.x;
StandLeft.y = StandRight.y;
RunRight.x = StandRight.x;
RunRight.y = StandRight.y;
RunLeft.x = StandRight.x;
RunLeft.y = StandRight.y;
HeroGroundTouch.x = StandRight.x;
HeroGroundTouch.y = StandRight.y;
HeroRoofTouch.x = StandRight.x;
HeroRoofTouch.y = StandRight.y;
HeroRightTouch.x = StandRight.x;
HeroRightTouch.y = StandRight.y;
HeroLeftTouch.x = StandRight.x;
HeroLeftTouch.y = StandRight.y;
jumpLeft.x = StandRight.x;
jumpLeft.y = StandRight.y;
jumpRight.x = StandRight.x;
jumpRight.y = StandRight.y;
PLATFORMS/HITTESTINGS
package
import flash.display.*;
import flash.text.*;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.ui.*;
import flash.utils.*;
import flash.geom.*;
import flash.net.*;
import flash.media.Sound;
import flash.media.SoundTransform;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Level1 extends Sprite
var i:int = 0;
var ExFloor=new exFloor();
var tFloor:exFloor = new exFloor ;
var arFloor = new Array();
var GroundSnapped:Boolean = false;
var bRemoveStage:Boolean = false;
var CurrentStage:int = 1;
var iStage:int = 1;
public function Level1()
GenerateLevel1();
public function PlaceFloor(nx:int,ny:int,nWidth:int,nHeight:int):void
tFloor = new exFloor ;
addChild(tFloor);
arFloor.push(tFloor);
tFloor.x = nx;
tFloor.y = ny;
tFloor.width = nWidth;
tFloor.height = nHeight;
public function TouchingGround(HeroGroundTouch:Sprite):Boolean
for (i=0; i<arFloor.length; i++)
if (HeroGroundTouch.hitTestObject(arFloor[i]))
GroundSnapped = true;
return true;
if (HeroGroundTouch.hitTestObject(arFloor[1]))
bRemoveStage = true;
CurrentStage+=1;
iStage+=1;
//return false;
return false;
public function TouchingRoof(HeroRoofTouch:Sprite):Boolean
for (i=0; i<arFloor.length; i++)
if (HeroRoofTouch.hitTestObject(arFloor[i]))
return true;
return false;
public function TouchingLeft(HeroLeftTouch:Sprite):Boolean
for (i=0; i<arFloor.length; i++)
if (HeroLeftTouch.hitTestObject(arFloor[i]))
return true;
return false;
public function TouchingRight(HeroRightTouch:Sprite):Boolean
for (i=0; i<arFloor.length; i++)
if (HeroRightTouch.hitTestObject(arFloor[i]))
return true;
return false;
function GenerateLevel1():void
PlaceFloor(435,7,519,36);
PlaceFloor(1055,522,100,19);//NextLevelPlatform
PlaceFloor(105,178,275,32);
PlaceFloor(-160,368,875,22);
PlaceFloor(-405,521,1360,18);// Ground
PlaceFloor(-405,8,480,35);//
PlaceFloor(-405,-140,12,679);//
PlaceFloor(943,-139,12,491);//
PlaceFloor(943,353,12,166);// Door
PlaceFloor(-393,-139,1339,6);//
PlaceFloor(957,522,95,19);
function GenerateLevel2():void
PlaceFloor(-398,507,1345,20);//Ground
PlaceFloor(978,509,189,15);
PlaceFloor(-397,190,363,17);
PlaceFloor(542,190,404,18);
PlaceFloor(151,314,218,11);
PlaceFloor(-49,8,16,199);
PlaceFloor(-34,153,135,13);
PlaceFloor(541,6,18,202);
PlaceFloor(211,38,98,9);
PlaceFloor(372,153,171,11);
PlaceFloor(-398,78,106,8);
PlaceFloor(-157,11,121,11);
PlaceFloor(558,7,98,13);
PlaceFloor(842,87,104,11);
make your ground larger so it's easier to detect contact between your character and the ground. ie, increase its height.
because you probably don't want to change the ground that the user sees, add an alpha=0 shape to your ground. it will look the same but contact will be detected with the current shapes that make up your ground and the alpha=0 shape.
then fix the glitch where it appears the character is falling below the top of the ground. do that by moving the character as soon as contact is detected. -
Hi Guys:
Have 2 unable solve issues, would be much appreciated if anyone could help.
// ISSUE 1 //
I am experiencing an issue with Load & Unload Movie. What happen is that I am trying to load an external SWF into a movie clip call movieContainer in my main website. This external SWF file has timeline that perform a animation when it's loaded into the movieContainer.
I can load and unload the movie with no problem...the issue is that after I unload the SWF and then at any point of the movie on the main website I click to load the SWF back to the stage.....the timeframe of the SWF file stay at where it get left off(when it's unloaded). I am trying to make it play start all over again.
I try the movieContainer.content.gotoAndPlay(1); but it doesn't do anything. Any idea how I could make this work?
Here is my code:
var content:Loader = new Loader();
content.load(new URLRequest("externalSwf/content.swf"));
loadMovieButton.addEventListener(MouseEvent.CLICK, loadMovieButtonClicked);
function loadMovieButtonClicked(e:MouseEvent):void{
movieContainer.addChild(content);
// ISSUE 2 //
In my external SWF file, I have create a loading loader at the 1st frame. But it doesn't play all the time when I testing on the server. It works just fine when I test locally with TEST MOVIE. Not only it doesn't play all the time.....it suppose to play from 2nd frame of the movie after the loading is finished (I have a short animation play between frame 2 - frame 20) Instead of playing from frame 2 to frame 20, the animation just jump straight to frame 20...which mean the user won't see the animation between frame 2 - frame 20.
import flash.events.ProgressEvent;
function update(e:ProgressEvent):void
var percent:Number = Math.floor( (e.bytesLoaded*100)/e.bytesTotal );
if(preloaderMC is MovieClip){
preloaderMC.gotoAndStop(percent);
//preload_txt.text = String(percent);
if(percent == 100){
gotoAndPlay(2);
loaderInfo.addEventListener(ProgressEvent.PROGRESS, update);
// Extra test for IE
var percent:Number = Math.floor( (this.loaderInfo.bytesLoaded*100)/this.loaderInfo.bytesTotal );
if(percent == 100){
nextFrame();
stop();
Many Thanks!Thanks for the reply, the code I use to load the external SWF is:
The button is within a movieClip: commercialScrollBar_mc
The button instance name is: stackPancakeBar
The external SWF get to load into a movieClip container call: projectDetailsContainer_mc
var ldr:Loader = new Loader();
ldr.load(new URLRequest("projectsCommercial/stackPancakeBar.swf"));
commercialScrollBar_mc.stackPancakeBar.addEventListener(MouseEvent.CLICK, stackPancakeBarClicked);
function stackPancakeBarClicked(e:MouseEvent):void{
MovieClip(ldr.content).gotoAndPlay(1);
projectDetailsContainer_mc.addChild(ldr);
I was thinking does it has anything to do with the UNLOAD script I have on the external SWF file? Below are the code for removing the child.
back_btn.addEventListener(MouseEvent.CLICK, removeProjectDetails);
function removeProjectDetails(e:MouseEvent):void{
this.parent.parent.removeChild(this.parent);
Thanks Heaps, by the way, do you have any idea why the loading sequence doesn't get to play every time? Or perhape the file size is too small? -
I'm trying to finish this code for a class project, and I keep getting this "
TypeError: Error #1010: A term is undefined and has no properties.
at ViolaMobileGameStudentsVersion_fla::MainTimeline/gameLoop()"
I've debugged it and it's said that the issue is at frame 86, which is
"menuScreen.level_txt.text = String(level);"
Here's the whole code, it's kind of long but I can't figure anything out. All the texts have their proper names.
Any suggestions are appreciated, I have to have this turned in by saturday..
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.media.Sound;
import flash.net.SharedObject;
import flash.events.MouseEvent;
/**************VARIABLES**************/
var STATE_INIT_GAME:String = "STATE_INIT_GAME";
var STATE_START_PLAYER:String = "STATE_START_PLAYER";
var STATE_PLAY_GAME:String = "STATE_PLAY_GAME";
var STATE_END_GAME:String = "STATE_END_GAME";
var gameState:String;
var player:MovieClip;
var enemies:Array;
var level:Number;
var score:Number;
var lives:Number;
var Bullet:Array;
//var bulletTimer:Timer = new Timer(200); // do not add this line
var explosions:Array;
var spaceKey:Boolean = false;
var rightKey:Boolean = false;
var leftKey:Boolean = false;
var upKey:Boolean = false;
var downKey:Boolean = false;
var accel:Accelerometer;
var hiddenOptions:Boolean = true;
/**************SETUP**************/
gameOverScreen.visible = false;
optionsMenu.visible = false;
stage.addEventListener(KeyboardEvent.KEY_DOWN, watchKeys);
stage.addEventListener(KeyboardEvent.KEY_UP, resetKey);
stage.addEventListener(KeyboardEvent.KEY_UP, optionsKey);
/**************INTRO SCREEN**************/
titleScreen.play_btn.addEventListener(MouseEvent.CLICK, clickAway);
function clickAway(event:MouseEvent):void
moveScreenOff(titleScreen);
//Gesture Swipe
Multitouch.inputMode = MultitouchInputMode.GESTURE;
titleScreen.addEventListener(TransformGestureEvent.GESTURE_SWIPE, swipeAway);
function swipeAway(event:TransformGestureEvent):void
//Swipe Left
if (event.offsetX == -1)
moveScreenOff(titleScreen);
function moveScreenOff(screen:MovieClip):void
var introTween = new Tween(screen,"x",Strong.easeInOut,screen.x,(screen.width)*-1,1,true);
introTween.addEventListener(TweenEvent.MOTION_FINISH, tweenFinish);
function tweenFinish(e:TweenEvent):void
gameState = STATE_INIT_GAME;
addEventListener(Event.ENTER_FRAME, gameLoop);
we stopped here
/**************GAME STATES**************/
function gameLoop(e:Event):void
menuScreen.level_txt.text = String(level);
menuScreen.score_txt.text = String(score);
menuScreen.lives_txt.text = String(lives);
switch (gameState)
case STATE_INIT_GAME :
initGame();
break;
case STATE_START_PLAYER :
startPlayer();
break;
case STATE_PLAY_GAME :
playGame();
break;
case STATE_END_GAME :
endGame();
break;
/**************STATE_INIT_GAME**************/
function initGame():void
player = new Player();
enemies = new Array();
Bullet = new Array();
explosions = new Array();
level = 1;
score = 0;
lives = 3;
fire_btn.visible = true;
gameState = STATE_START_PLAYER;
/**************STATE_START_PLAYER**************/
function startPlayer():void
player.x = stage.stageWidth / 2;
player.y = stage.stageHeight - player.height;
player.cacheAsBitmap = true;
addChild(player);
accel = new Accelerometer();
if (Accelerometer.isSupported)
accel.addEventListener(AccelerometerEvent.UPDATE, accelMove);
else
//If there is no accelerometer support...
addEventListener(Event.ENTER_FRAME, movePlayer);
gameState = STATE_PLAY_GAME;
function accelMove(event:AccelerometerEvent):void
player.x -= event.accelerationX * 100;
player.y += event.accelerationY * 80;
if (player.x < 0)
player.x = 0;
else if (player.x > (stage.stageWidth - player.width) )
player.x = stage.stageWidth - player.width;
if (player.y < 50)
player.y = 50;
else if (player.y > stage.stageHeight - player.height)
player.y = stage.stageHeight - player.height;
addEventListener(MouseEvent.CLICK,fire);
function fire(evt:MouseEvent):void
createBullet();
function movePlayer(Evt:Event):void
if (rightKey)
player.x += 10;
else if (leftKey)
player.x -= 10;
if (upKey)
player.y -= 4;
else if (downKey)
player.y += 4;
if (spaceKey)
createBullet();
if (player.x < 0)
player.x = 0;
else if (player.x > stage.stageWidth - player.width)
player.x = stage.stageWidth - player.width;
if (player.y < 50)
player.y = 50;
else if (player.y > stage.stageHeight - player.height)
player.y = stage.stageHeight - player.height;
function createBullet():void
var tempBullet:MovieClip = new Bullets();
tempBullet.x = player.x;
tempBullet.y = player.y;
tempBullet.cacheAsBitmap = true;
tempBullet.speed = 15;
addChild(tempBullet);
Bullet.push(tempBullet);
function moveBullet():void
var tempBullet:MovieClip;
for (var i=Bullet.length-1; i>=0; i--)
tempBullet = Bullet[i];
tempBullet.y -= tempBullet.speed;
if (tempBullet.y < 0)
removeBullet(i);
var tempExplosion:MovieClip;
for (i=explosions.length-1; i>=0; i--)
tempExplosion = explosions[i];
if (tempExplosion.currentFrame >= tempExplosion.totalFrames)
removeExplosion(i);
/**************STATE_PLAY_GAME**************/
function playGame():void
makeEnemies();
moveEnemies();
moveBullet();
testForEnd();
function makeEnemies():void
var chance:Number = Math.floor(Math.random() * 60);
var whichEnemy:Number = Math.round(Math.random() * 2 + 1);
if (chance <= 1 + level)
var tempEnemy:MovieClip;
tempEnemy = new Enemy();
tempEnemy.gotoAndStop(whichEnemy);
tempEnemy.speed = 3;
tempEnemy.x = Math.round((Math.random() * 800) + 20);
tempEnemy.cacheAsBitmap = true;
addChild(tempEnemy);
enemies.push(tempEnemy);
setChildIndex(menuScreen,numChildren-1);
function moveEnemies():void
var tempEnemy:MovieClip;
for (var i:int =enemies.length-1; i>=0; i--)
tempEnemy = enemies[i];
tempEnemy.y += tempEnemy.speed;
if (tempEnemy.y > stage.stageHeight)
removeEnemy(i);
lives--;
else if (tempEnemy.hitTestObject(player))
makeExplosion(tempEnemy.x, tempEnemy.y);
removeEnemy(i);
lives--;
var tempBullet:MovieClip;
//tempEnemy = enemies[i];
for (var j:int=Bullet.length-1; j>=0; j--)
tempBullet = Bullet[j];
if (tempEnemy.hitTestObject(tempBullet))
makeExplosion(tempEnemy.x, tempEnemy.y);
removeEnemy(i);
removeBullet(j);
score += 5;
function makeExplosion(ex:Number, ey:Number):void
var tempExplosion:MovieClip;
tempExplosion = new Explosion();
tempExplosion.x = ex;
tempExplosion.y = ey;
addChild(tempExplosion);
explosions.push(tempExplosion);
//var sound:Sound = new Explode();
//sound.play();
function testForEnd():void
if (score > level * 100)
level++;
if (lives == 0)
gameState = STATE_END_GAME;
function removeEnemy(idx:int)
removeChild(enemies[idx]);
enemies.splice(idx,1);
function removeBullet(idx:int)
removeChild(Bullet[idx]);
Bullet.splice(idx,1);
function removeExplosion(idx:int)
removeChild(explosions[idx]);
explosions.splice(idx,1);
/*********** KEY PRESS ***********/
function watchKeys(evt:KeyboardEvent):void
if (evt.keyCode == Keyboard.SPACE)
spaceKey = true;
if (evt.keyCode == Keyboard.RIGHT)
rightKey = true;
if (evt.keyCode == Keyboard.LEFT)
leftKey = true;
if (evt.keyCode == Keyboard.UP)
upKey = true;
if (evt.keyCode == Keyboard.DOWN)
downKey = true;
function resetKey(evt:KeyboardEvent):void
if (evt.keyCode == Keyboard.SPACE)
spaceKey = false;
if (evt.keyCode == Keyboard.RIGHT)
rightKey = false;
if (evt.keyCode == Keyboard.LEFT)
leftKey = false;
if (evt.keyCode == Keyboard.UP)
upKey = false;
if (evt.keyCode == Keyboard.DOWN)
downKey = false;
/**************END SCREEN**************/
function endGame():void
accel.removeEventListener(AccelerometerEvent.UPDATE, accelMove);
removeEventListener(Event.ENTER_FRAME, gameLoop);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, watchKeys);
stage.removeEventListener(KeyboardEvent.KEY_UP, resetKey);
fire_btn.enabled = false;
fire_btn.visible = false;
removeEventListener(MouseEvent.CLICK,fire);
removeGame();
gameOverScreen.visible = true;
gameOverScreen.x = 0;
showResults();
/**************REMOVE GAME**************/
function removeGame():void
for (var i:int = enemies.length-1; i >=0; i--)
removeEnemy(i);
for (var j:int = Bullet.length-1; j >=0; j--)
removeBullet(j);
for (var k:int = explosions.length-1; k >=0; k--)
removeExplosion(k);
removeChild(player);
function showResults():void
gameOverScreen.enter_btn.visible = false;
gameOverScreen.nameField_txt.visible = false;
var so:SharedObject = SharedObject.getLocal("alltimeHighScore");
if (so.data.score == undefined || score > so.data.score)
gameOverScreen.highScore_txt.text = "You made it to level " + level + " with a high score of " + score + ". \n Enter your name below.";
gameOverScreen.enter_btn.visible = true;
gameOverScreen.nameField_txt.visible = true;
else
gameOverScreen.highScore_txt.text = "Your score of " + score + " \n does not beat " + so.data.score + " \n by " + so.data.name;
gameOverScreen.quit_btn.addEventListener(MouseEvent.CLICK, exitApp);
gameOverScreen.enter_btn.addEventListener(MouseEvent.CLICK, clickEnter);
function clickEnter(event:MouseEvent):void
gameOverScreen.highScore_txt.text = "Great job, " + gameOverScreen.nameField_txt.text + "! \n You made it to level " + level + " \n with a score of " + score + "!";
so.data.score = score;
so.data.level = level;
so.data.name = gameOverScreen.nameField_txt.text;
so.flush();
gameOverScreen.enter_btn.visible = false;
gameOverScreen.nameField_txt.visible = false;
//Enables the play button
gameOverScreen.playAgain_btn.addEventListener(MouseEvent.CLICK, clickFinalAway);
function clickFinalAway(event:MouseEvent):void
moveScreenOff(gameOverScreen);
/**************OPTIONS MENU**************/
function optionsKey(event:KeyboardEvent):void
//Options menu, use 16777234 or Keyboard.MENU
if (event.keyCode == 16777234)
if (hiddenOptions)
setChildIndex(optionsMenu,numChildren-1);
optionsMenu.visible = true;
optionsMenu.addEventListener(MouseEvent.CLICK, exitApp);
pauseGame();
else
optionsMenu.visible = false;
optionsMenu.removeEventListener(MouseEvent.CLICK, exitApp);
resumeGame();
hiddenOptions = ! hiddenOptions;
function exitApp(event:MouseEvent):void
//NativeApplication.nativeApplication.exit(0);
//Keep screen awake if you are using the Accelerometer etc.
//NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
stage.addEventListener(Event.DEACTIVATE, Deactivate);
function Deactivate(event:Event):void
pauseGame();
stage.addEventListener(Event.ACTIVATE, Activate);
function Activate(event:Event):void
resumeGame();
function pauseGame():void
//Remove any listener events, timers etc.
if (gameState == STATE_PLAY_GAME)
removeEventListener(Event.ENTER_FRAME, gameLoop);
accel.removeEventListener(AccelerometerEvent.UPDATE, accelMove);
removeEventListener(MouseEvent.CLICK,fire);
function resumeGame():void
//Activate any listener events, timers etc.
if (gameState == STATE_PLAY_GAME)
addEventListener(Event.ENTER_FRAME, gameLoop);
accel.addEventListener(AccelerometerEvent.UPDATE, accelMove);
addEventListener(MouseEvent.CLICK,fire);I don't see where menuScreen is intialized... It's also long after this was due, hope you figured it out.
-
AddChild/RemoveChild Problem
Hi, I had posted this in the FlashBuilder forum but someone very kindly suggested I post it here instead. So that's what I'm doing.
I'm using FlashBuilder4 (set to Flex 3.5SDK for compatibility) and am running into an issue with RemoveChild/AddChild.
I have a TabNavigator component with several tabs, each tab utilizing a canvas as its child component.
What I'd like to do is to be able to click a button and have one of the tabs, say the first (index 0) inaccessbile, then to make it accessible upon clicking another button. My first thought was to disable the canvas for the first tab, but I don't see a property for that (i.e. no tabnavigator1.getChildAt(0).enabled property). But I DO see a "visible" property; unfortunately, doing a "tabnavigator1.getChildAt(0).visible = false" in the button's click handler doesn't seem to work. So I settled on removeChild. Clicking the first button calls a handler with "tabnavigator1.removeChild(canvas0)", where canvas0 is the child of the first tab, works fine. Unfortunately, to restore the child I use, in the clickhandler of the SECOND button, "tabnavigator1.addChildAt(canvas0,0);tabnavigator1.selectedIndex = 0" and this does cause the first tab to be selected BUT THE CONTENTS OF THE PREVIOUSLY DISPLAYED TAB OVERWRITE CANVAS0 (sorry for shouting, just wanted to emphasize).
The above seems to be an issue (for me at least) with addChild, since when I started playing with the new way FlashBuilder handles states, using Add/Remove Child, I would see the same type of behavior; i.e. one tab's contents overwriting another's.
Has anyone run into this issue (I've searched and don't see anything)? Failing that, any ideas what might be going on and what to do to correct/workaround this issue?
Thanks.hi
not sure if it will fix your problem but you can enable/disable Canvas.
instead of this:
tabnavigator1.getChildAt(0).enabled = false;
do this:
(tabnavigator1.getChildAt(0) as Canvas).enabled = false;
(FB doesnt know what kind of object getChildAt(0) is, so you have to help it out by specifying the type)
Maybe you are looking for
-
I have a MBP that was recently subjected to some liquid damage and taken in for repair. While it was being repaired, I purchased a second MBP. My newest MBP is now my personal laptop, and I'm converting the old one over to a work laptop. In that p
-
How to generate web services for OAS with wsdl extension
Hi, I wanted to know how to generate web services from Oracle Application Server especially with .wsdl extension and with document/literal style. I know that earlier there was a tool called SmartConnect from BEA WebLogic. But that will work only with
-
Publish WS to SR error. HELP!!!
T-code: WSPUBLISH when we publish the service to SR got this error... ok Services Registry name : SR_UDDI. Logical port : LP_WORKPLACE. ok Services Registry version is 1.1. ok Physical system validated successfully. ok Classification system cache
-
ive got a new pc with windows 7 and my ipod touch 4th gen is synced with my old pc ,how can i back up the photos and music on the ipod to my new pc ?
-
EPM Multi language support for custom list in demand management
Dear Team, We have installed EPM 2013 with English as base language and Arabic language pack as secondary language. We have implemented demand management and portfolio management as part of EPM implementation. Currently demand management have some wo