SEARCH YOUR SOLUTION HERE  

Flash Replacing array and removing previous children

all.

I have a problem with replacing values in an array.

I have this code that takes the string values out of an XML file:
Code: publicfunction loadXML(xml:Event):void { container = new XML(xml.target.data); var aantalSommen:Number = container.somTotaal.length() -1; var randomSom:Number = Math.round(Math.random()*aantalSommen); uitkomstGetal = container.somTotaal.uitkomst.text()[randomSom]; trace("Uitkomst getal: "+uitkomstGetal) deSom = container.somTotaal.som.text()[randomSom]; trace("De som: "+deSom) Ballen = container.somTotaal.andereGetallen.text()[randomSom] +","+ container.somTotaal.uitkomst.text()[randomSom]; trace("Extra ballen: "+Ballen)getallenRij = Ballen.split(",");
And then this code inside a function which adds a new child (tijdelijkeBal) for every string in the array:

Code: for each (var buttonArray:String in getallenRij){ tijdelijkeBal = new Getal((String)(buttonArray)); tijdelijkeBal.x = Math.random() * stage.stageWidth; tijdelijkeBal.y = Math.random() * stage.stageHeight; addChild(tijdelijkeBal); tijdelijkeBal.mouseChildren = false; ballenRij.push(tijdelijkeBal); }
And I have this in my constructor function: Code: lader.addEventListener(Event.COMPLETE, loadXML); lader.load(new URLRequest("sommen/plus.xml")); So far so good. Every time I reload my application, it takes a random set of 5 strings from the XML and it adds the 5 children.

What I want to do is reload the XML so that the previous added childred are replaced with new ones when I execute another lader.load(new URLRequest("sommen/plus.xml"));

Right now it's so that whenever I load a new URLRequest for the XML file it just adds new children and leaves the previous ones there.


I tried doing removeChild(tijdelijkeBal); but that just removes one child. I think the last one in the array in fact.


I hope this made sense.

Posted On: Thursday 25th of October 2012 09:29:17 PM Total Views:  295
View Complete with Replies




Related Messages:

Can you have flash do stuff after the swf is closed?   (101 Views)
Hi all, I'm writing a Flash game for a class that is supposed to test elementary kids' math skills. After each activity is completed, Flash sends the results to our database (e.g., that 8/10 math problems were answered correctly). If the user is in the middle of an activity and hits our Logout button, we'll send what results they had to the database anyway. But if the user closes out of the browser in the middle of an activity, is there a way to quickly send stuff to the database before the swf dies
jQuery.flashgallery Width&Height on AS3   (93 Views)
fellas I'm using a software called "Photo Gallery Builder" that generates SWF interactive slideshows, along with some JavaScript files and HTML. Now, I've successfully imported the final SWF file to a child on stage, thing is I'm having trouble in resizing the swf slideshow inside it. I've used ActionScript Code: var Xwidth:Number = 1024; var Yheight:Number = 600; loader.width = Xwidth; // Doesn't work, mc not displayed loader.height = Yheight; // Doesn't work, mc not displayed scaleX = Xwidth; // Doesn't work, mc not displayed scaleY = Yheight; // Doesn't work, mc not displayed What does work is (but it looks like crap): ActionScript Code: loader.scaleX = 0.9; loader.scaleY = 0.68; Inside the HTML file (which I'm not going to use at all) I find: PHP Code: jQuery.flashgallery('gallery/gallery.swf','gallery/config.xml',{width:'1024px',height:'600px',background:'transparent'}); I assume is that the size I set for the swf on the slideshow generator is exported to the HTML and defined via JavaScript, and that allows the browser to resize the sideshow and its menu. But when I change the proportions of it inside flash, it distorts everything. I might be trying to do something impossible, once the javascript should only be used by the browser when I run the HTML, and not by the swf file I'm importing. So is there any way to resize the slideshow via AS3 like it happens via JS Thx in advance!
Loading a swf file in another flash file   (121 Views)
I have a website.fla and want to add a slideshow.swf to one of the pages.
remove flash player setting when use from mic   (107 Views)
hi every body . i want dont show flash player setting window when i use from microphone in my program . how this possible.
Is there a way for flash to detect language/country?   (130 Views)
I need flash to show English or French depending on what language/country you're from. I know you can do it with javascript to do a browser detect. Just wondering if you can do it in flash.
How to upload sounds to a flash site   (143 Views)
, i'm a little noob about As3 indeed i'm three days since my first exam on flash, and i'm almost done completing my personal site. I have followed a tutorial to built a simple music player with play stop and mute buttons and only one track loaded. And it's working fine when i try the site on my computer, but when i upload the flash site on altervista and test it online the track file isn't loading Here is my musicplayer code: Thx for the help and sry for my bad english Quote: // spectrum constants const SPECTRUM_HEIGHT:int = 75; const CHANNEL_LENGTH:int = 256; const SPECTRUM_LEFT_FILL_COLOR:uint = 0x5FDEFE; const SPECTRUM_LEFT_FILL_ALPHA:Number = 0.5; const SPECTRUM_LEFT_LINE_COLOR:uint = 0x013643; const SPECTRUM_RIGHT_FILL_COLOR:uint = 0xBFF075; const SPECTRUM_RIGHT_FILL_ALPHA:Number = 0.5; const SPECTRUM_RIGHT_LINE_COLOR:uint = 0x4A730D; // vars var sndObject:Sound = new Sound(); var chaObject:SoundChannel = new SoundChannel() ; var sndTransform:SoundTransform = new SoundTransform(); var reqObject:URLRequest = new URLRequest("CHEMICAL.mp3"); var sndBytes:ByteArray = new ByteArray(); var intPosition:int = 0; var bolStop:Boolean = true; function initMP3Player():void { // set event listeners addEventListener(Event.ENTER_FRAME, renderSpectrum); addEventListener(Event.ENTER_FRAME, calcProgress); this.mcMp3Player.btnStop.addEventListener(MouseEve nt.CLICK, stopPlayback); this.mcMp3Player.btnPause.addEventListener(MouseEv ent.CLICK, pausePlayback); this.mcMp3Player.btnPlay.addEventListener(MouseEve nt.CLICK, startPlayback); this.mcMp3Player.btnMute.addEventListener(MouseEve nt.CLICK, mutePlayback); this.mcMp3Player.btnUnmute.addEventListener(MouseE vent.CLICK, unmutePlayback); this.mcMp3Player.progress.addEventListener(MouseEv ent.CLICK, setNewProgress); // use hand cursor for progress bar this.mcMp3Player.progress.buttonMode = true; this.mcMp3Player.btnPause.visible = false; this.mcMp3Player.btnUnmute.visible = false; } function stopPlayback(e:MouseEvent):void { chaObject.stop(); sndObject = new Sound(); bolStop = true; intPosition = 0; this.mcMp3Player.btnPlay.visible = true; this.mcMp3Player.btnPause.visible = false; } function pausePlayback(e:MouseEvent):void { this.mcMp3Player.btnPlay.visible = true; this.mcMp3Player.btnPause.visible = false; playSound(false); } function startPlayback(e:MouseEvent):void { this.mcMp3Player.btnPlay.visible = false; this.mcMp3Player.btnPause.visible = true; playSound(); } function mutePlayback(e:MouseEvent):void { this.mcMp3Player.btnMute.visible = false; this.mcMp3Player.btnUnmute.visible = true; setVolume(0); } function unmutePlayback(e:MouseEvent):void { this.mcMp3Player.btnMute.visible = true; this.mcMp3Player.btnUnmute.visible = false; setVolume(1); } function setNewProgress(e:MouseEvent):void { var p:int = sndObject.length * e.currentTarget.mouseX / 220; chaObject.stop(); chaObject = sndObject.play(p); this.mcMp3Player.btnPlay.visible = false; this.mcMp3Player.btnPause.visible = true; } function playSound(bolPlay:Boolean = true):void { if(bolPlay) { if(bolStop) { // load mp3 file if playback has been stopped sndObject.load(reqObject); bolStop = false; } else { intPosition = chaObject.position; } chaObject = sndObject.play(intPosition); } else { chaObject.stop(); } } function setVolume(intVolume:int = 1):void { sndTransform.volume = intVolume; chaObject.soundTransform = sndTransform; } function calcProgress(e:Event):void { var p:MovieClip = this.mcMp3Player.progress.mcProgressFill; var w:int = Math.round( 220 * chaObject.position / sndObject.length); p.width = w; } function renderSpectrum(e:Event):void { // set a reference to the spectrum graphics var g:Graphics = this.mcMp3Player.spectrum.graphics; // compute spectrum in byte array sndBytes SoundMixer.computeSpectrum(sndBytes); /* * LEFT CHANNEL */ g.clear(); g.lineStyle(0, SPECTRUM_LEFT_LINE_COLOR); g.beginFill(SPECTRUM_LEFT_FILL_COLOR, SPECTRUM_LEFT_FILL_ALPHA); g.moveTo(0, SPECTRUM_HEIGHT); var n:Number = 0; for (var i:int = 0; i < CHANNEL_LENGTH; i++) { n = (sndBytes.readFloat() * SPECTRUM_HEIGHT); g.lineTo(i * 2, SPECTRUM_HEIGHT - n); } g.lineTo(CHANNEL_LENGTH * 2, SPECTRUM_HEIGHT); g.endFill(); /* * RIGHT CHANNEL */ g.lineStyle(0, SPECTRUM_RIGHT_LINE_COLOR); g.beginFill(SPECTRUM_RIGHT_FILL_COLOR, SPECTRUM_RIGHT_FILL_ALPHA); g.moveTo(CHANNEL_LENGTH * 2, SPECTRUM_HEIGHT); for (i = CHANNEL_LENGTH; i > 0; i--) { n = (sndBytes.readFloat() * SPECTRUM_HEIGHT); g.lineTo(i * 2, SPECTRUM_HEIGHT - n); } g.lineTo(0, SPECTRUM_HEIGHT); g.endFill(); } initMP3Player();
reading flashvars   (148 Views)
hello, I have a flash swf of 1.2mb. am embeding it with swfobject using dynamic embeding . script type="text/javascript"> var flashvars = {}; flashvars.campaignid = "12345678890"; var params = {}; params.allowscriptaccess = "always"; var attributes = {}; swfobject.embedSWF("soccer.swf", "myAlternativeContent", "550", "400", "10.0.0", false, flashvars, params, attributes); am tring to read campaignid inside my document class ... the code is like ActionScript Code: public function Main() { loaderInfo.addEventListener(ProgressEvent.PROGRESS,update); loaderInfo.addEventListener(Event.COMPLETE,onLoadedMovie); } private function update(e:ProgressEvent):void { } private function onLoadedMovie(e:Event) { campId=this.root.loaderInfo.parameters["campaignid"]; } when i alert the value i got null when i use the same method in a small file it works.. can anyone help me regards
How to change xmlFilePath using flashvars?   (163 Views)
I have a multilingual website and try to change title and caption of my flash slideshow based on selected language. I already created a xml file which is opml. In opml file there is RSS type url bodto.com.tr/Haberler/BODTONewsRss.aspxlang=tr If we would add lang=en in URL which produces XML File in bodto.com.tr/kik.aspxlang=en, it displays RSS type English version like in the following, bodto.com.tr/Haberler/BODTONewsRss.aspxlang=en What I try to achieve is to fetch lang=tr|en from url and pass it to SSP for flash in order to display deed language based on selection but I do not know how! What I did so far is in the following. Please correct me if I am wrong because I am not a flash guy at all. Code: var flashvars = { xmlFilePath: escape("bodto.com.tr/kik.aspx"), xmlFileType: "OPML", //lang: "getQueryParamValue('lang')" initialURL: escape(document.location) } var params = { bgcolor: "#000000", allowfullscreen: "true", wmode:"transparent", allowScriptAccess: "always" } var attributes = {} swfobject.embedSWF("/swf/slideshowpro.swf", "flashcontent", "550", "400", "10.0.0", false, flashvars, params, attributes); I am using Adobe Flash 5.5 and In component paramaters of SSP I left XML File Path blank and set "Default" to XML File Type. After that I created a layer on SPP instance and gave Slideshow Player Instance a name my_ssp then on action frame of layer I added the following Code: var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters; for (var param in paramObj) { if (param == "xmlfile") { my_ssp.xmlFilePath = paramObj[param]; } if (param == "xmlfiletype") { my_ssp.xmlFileType = paramObj[param]; } } I hope someone out there would give me some feedback in order to resolve it.
[AS3] Can't get a simple flash.display.Loader to work   (152 Views)
This might be easy for many of you to debug. What in the world can I possibly be doing wrong! The MovieClip art Gallery is added to the stage just fine, but it's .as class can't even display a simple image 'elephant.jpg'. Please help! ActionScript Code: package { import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; import flash.display.Loader; import flash.display.LoaderInfo; import flash.net.URLRequest; import flash.events.ProgressEvent; public class ArtGallery extends MovieClip { // load/set Vars var myLoader:Loader = new Loader(); public function ArtGallery() { addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); } private function onAddedToStage(event:Event):void { //Add event listeners addEventListener(Event.ENTER_FRAME, onEnterFrame); addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage); // add eventlisteners to the property of myLoader called contentLoaderInfo myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoaderProgress); myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete); } private function onRemovedFromStage(event:Event):void { removeEventListener(Event.ENTER_FRAME, onEnterFrame); removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage); removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage); } var fileRequest:URLRequest = new URLRequest("elephant.jpg"); myLoader.load(fileRequest); public function onProgressStatus(event:ProgressEvent) { trace(event.bytesLoaded, event.bytesTotal); } public function onLoaderReady(event:Event) { addChild(myLoader); } private function onEnterFrame(event:Event):void { trace("I'M Here!"); } } } The errors: Quote: \ArtGallery.as, Line 30 1120: Access of undefined property onLoaderComplete. ArtGallery.as, Line 29 1120: Access of undefined property onLoaderProgress. ArtGallery.as, Line 42 1120: Access of undefined property fileRequest. ArtGallery.as, Line 42 1120: Access of undefined property myLoader.
Are the images loaded in flash memorized into PC cache?   (133 Views)
i working on a project that load images localizend on a server. For optimize the RAM usage i remove the images when they aren't shown, and re-load them when is necessary. But are this images saved into the PC cache so that the second, third, forth... time that i call it, they will be loaded instantly Or flash need to download it every time from server
Web page within flash   (110 Views)
I've been looking around like a forensic scientist piecing together information for my latest project. Basically I need to display a particular webpage within my flash file... Now I know flash can display simple HTML, but nothing complex and nothing from an external source... BUT I know flash can also handle PHP - obviously. The page I need to load is a wordpress website, a combination of PHP codes and simple HTML snippets... but what I couldn't find was a way of inserting the snippets into a control box or movieclip on my page (actually run the PHP code to fetch HTML snippets) I hope it's possible!! (although it's seeming less and less likely the more I read up)
Shared object using a flash server   (114 Views)
At the moment I'm developing something in which I need to have a server of some sort store and send Shared Objects. When I was looking into it the API said that you would use something like a flash media server. Well the student price for that is about 1300$ so I can't do that. Is there a way for me to create a server in actionscript using socket connections (or something). To send and receive shared objects I haven't started on this yet I'm just looking ahead into what I'm going to need.
Editing flash application text content. Best way?   (176 Views)
, I'm creating a Flash presentation, and the user wants to be able to change the text on any screen from Flash itself. This was my original my idea (I don't have much experience in AS): 1 - Put all the text in a text file (XML or plain). 2 - Make AS read the text and fill in the text fields in the Flash presentation. 3 - When it's needed to change the text content, execute the Flash presentation with a parameter that will tell AS to show all the fields as INPUT. 4 - Save the new text in the text file via PHP. But I have been asked if it would be possible to avoid the use of a text file (and the server connection with PHP) and change the swf text content directly with AS. Is this possible I have been googling it but with no success. I have the idea that this wouldn't be possible but i don't know all the possibilites in the Flash environment.
build a scroll bar by action script in flash   (132 Views)
I would like to produce a fitting room system, and the users can adjust doll's size. In terms of shoulder, hip, and the length of both legs and arms by a horizontal scroll bar in this system. How could I control Action Script by Flash Please kindly share your experiences and opinions with us,
Linking external SWFs to the main flash file, Error 1120   (123 Views)
Please can someone help me with fixing this problem: I have made a menu bar and linked each separate swf file to the corresponding button. Upon testing my main movie, all the text on the main page is disappearing, the new swf file is not loading and the message 1120 error appears for all my buttons. I have checked the instance names and they match along with publish settings and folder settings. I cant understand why its not working Hope someone can help. Error: Scene 1, Layer 'Actions', Frame 1, Line 25 1120: Access of undefined property portfolio_btn. Code: var Xpos:Number = 180; var Ypos:Number = 200; var swf:MovieClip; var loader:Loader = new Loader(); var defaultSWF:URLRequest = new URLRequest("swfs/biography.swf"); loader.load(defaultSWF); loader.x = Xpos; loader.y = Ypos; addChild(loader); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Btns Universal function function btnClick(event:MouseEvent):void { removeChild(loader); var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.target.name + ".swf"); loader.load(newSWFRequest); loader.x = Xpos; loader.y = Ypos; addChild(loader); } // Btn listeners Biography_btn.addEventListener(MouseEvent.CLICK,bt nClick); portfolio_btn.addEventListener(MouseEvent.CLICK, btnClick); news_btn.addEventListener(MouseEvent.CLICK,btnClic k); gallery_btn.addEventListener(MouseEvent.CLICK,btnC lick); merchandise_btn.addEventListener(MouseEvent.CLICK, btnClick);
can I use mx.core.UIcomponent in flash   (128 Views)
I know it is intended for flex ... but what does that mean ... can I use it in flash ... if not, why not ... but more importantly: all of the mx classes, spark classes, flashx classes ... why are they NOT for flash pixels are pixels, matrices are matrices, 0's are 0's, 1's are 1's.
Limit flash loop to 30s   (128 Views)
actionscript users, I have a flash banner exactly like this one on a continuous loop. Does anyone know how can I stop the loop at the 30s mark That's one of the adwords requirements for flash banners. Thank you. pagead2.googlesyndication.com/pagead/imgadid=CIXd98qNhb6gcRDYBRhaMgjmHsz5dXlP0w
redirect browser from flash amfphp   (137 Views)
, I am currently developing an application in flash. In this application user will be able to buy in-game currency using real life money. For this purpose we have some external actors. In our case, it is hipay. Now, once a user clicks on a particular button, as3 will use amfphp to call a php file that eventually will do this: header("Location: ".$url) ; Once this happens I get an error in my flash: Error: Request for resource at https://test-payment.hipay.com/index...mevarialbes--- by requestor from http://mydomain.com/game.swf denied due to lack of policy file permissions Connection to https://test-payment.hipay.com/index...mevarialbes--- halted not permitted from http://mydomain.com/game.swf *** Security Sandbo Violation *** Warning: failed to load policyfile from https://test-payment.hipay.com/crossdomain.xml Now, is this a problem on my side or hipay's side. If it is the latter I'm screwed I guess and have to find another solution. Can anyone help me with this
Help creating a flash slideshow galary to show videos   (157 Views)
I am relatively new at using flash but need to create a flash slideshow galary to show videos. I found the link below and it is exactly how I want it to be shown and created. http://www.aleosoft.com/flashslidesh..._gallery3.html If anyone has any ideas of where I need to start to get this implemented I will be extremely grateful. Many
I need flash canvas menu ...   (181 Views)
.. I need an flash canvas menu, written in AS3... In any shape, any type, it doesn't matter... Please help...