New in as3. go to and play doesn't work - actionscript-3

I have a question about clicking movieclip to go to and play.
Anyway, this movieclips are dynamic, load from database use xml.
And when I clicked one of the images, it can go to and play to frame 37. but the image from database doesn't disappear. the blue box is in frame 37 and the images is in frame 1. i use script stop(); but the images still appear just like image number 1.
here is my code : the
import flash.text.TextField;
import flash.display.MovieClip;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.text.TextFieldAutoSize;
import flash.display.Sprite;
var yPlacement: int = 700;
var line1xpos: int = -10;
var line2xpos: int = -10;
var line3xpos: int = -10;
var distance: int = 200;
var loader: URLLoader = new URLLoader(new URLRequest("http://192.168.136.148/coba/imageLoopRC.php"));
loader.addEventListener("complete", xmlLoaded);
function xmlLoaded(event: Event): void {
var xmlData: XML = new XML(loader.data);
for each(var galleryFolder: XML in xmlData..galleryFolder) {
var galleryDir: String = galleryFolder.toString();
}
trace(xmlData);
var i: Number = 0;
for each(var menuXML: XML in xmlData..MenuItem) {
var picnum: String = menuXML.picnum.toString();
var thumb: String = menuXML.thumb.toString();
var nama: String = menuXML.nama.toString();
var namaTxt: TextField = new TextField();
namaTxt.autoSize = TextFieldAutoSize.CENTER;
namaTxt.textColor = 0xFE6795;
addChild(namaTxt);
var hargaTxt: TextField = new TextField();
hargaTxt.autoSize = TextFieldAutoSize.CENTER;
hargaTxt.textColor = 0xFE6795;
addChild(hargaTxt);
var thumbLdr: Loader = new Loader();
var thumbURLReq: URLRequest = new URLRequest(galleryDir + thumb);
thumbLdr.load(thumbURLReq);
var thumb_mc : MovieClip = new MovieClip();
thumb_mc.addChild(thumbLdr);
addChildAt(thumb_mc, 1);
if (picnum < "17") {
line1xpos = line1xpos + distance;
thumb_mc.x = line1xpos;
thumb_mc.y = yPlacement;
namaTxt.text = menuXML.nama.toString();
namaTxt.x = line1xpos;
namaTxt.y = thumb_mc.y + 130;
hargaTxt.text = "Rp " + menuXML.harga.toString();
hargaTxt.x = line1xpos;
hargaTxt.y = namaTxt.y + 15;
} else if (picnum > "16" && picnum < "23") {
line2xpos = line2xpos + distance;
thumb_mc.x = line2xpos;
thumb_mc.y = yPlacement + 200;
namaTxt.text = menuXML.nama.toString();
namaTxt.x = line2xpos;
namaTxt.y = thumb_mc.y + 130;
hargaTxt.text = "Rp " + menuXML.harga.toString();
hargaTxt.x = line2xpos;
hargaTxt.y = namaTxt.y + 15;
} else if (picnum > "22" && picnum < "29") {
line3xpos = line3xpos + distance;
thumb_mc.x = line3xpos;
thumb_mc.y = yPlacement + 400;
namaTxt.text = menuXML.nama.toString();
namaTxt.x = line3xpos;
namaTxt.y = thumb_mc.y + 130;
hargaTxt.text = "Rp " + menuXML.harga.toString();
hargaTxt.x = line3xpos;
hargaTxt.y = namaTxt.y + 15;
}
thumb_mc.addEventListener(MouseEvent.CLICK, clickToSeeStuff);
function clickToSeeStuff(event: MouseEvent): void {
gotoAndPlay(37);
}
}
}
Please help me to fix this.
Forgive my bad English. thanks anyway

I think you just set the property of movieclips visibility to false
someMC.visible = false;

Related

How to create a loop for caching images by AS3?

I have 100 movieclip on the stage, named ads_box_1 ... ads_box_100.there is another movieclip in each ads_box, named photo_box.I want cache 100 images(1.jpg,2.jpg,...,100.jpg) from server and add them to each ads_box.photo_box.I try some loops to do that,but they didn't work.So what is the solution?this my code:
import org.sgmnt.lib.net.*;
import flash.net.URLRequest;
import flash.filesystem.File;
for (var i:Number=1; i<=5; i++)
{
this["ads_box_" + i].photo_box.alpha = 0;
}
LocalCacheSettings.WORKING_DIRECTORY = File.applicationStorageDirectory;
//how to create a loop frome here...
var pic_loader:Loader;
NetClassFactory.initialize( LocalCacheLoader, LocalCacheURLLoader, LocalCacheNetStream );
pic_loader = NetClassFactory.createLoader();
pic_loader.contentLoaderInfo.addEventListener( Event.COMPLETE, _onComplete );
var pic_string:String = "http://localhost/Pics/" + String(1) + ".jpg";
pic_loader.load( new URLRequest(pic_string));
function _onComplete(e:Event):void
{
var new_pic_mc:Sprite= new Sprite();
new_pic_mc.addChild(pic_loader);
new_pic_mc.width = new_pic_mc.height = 90;
this["ads_box_" + 1].photo_box.addChild(new_pic_mc);
this["ads_box_" + 1].photo_box.alpha = 1;
}
//to here
Do something like this, note that this just loads the images in a sequential loop. You should also add event listeners for error handling. You will have to write the caching logic on top of this:
import org.sgmnt.lib.net.*;
import flash.net.URLRequest;
import flash.filesystem.File;
for (var i:Number=1; i<=5; i++)
{
this["ads_box_" + i].photo_box.alpha = 0;
}
LocalCacheSettings.WORKING_DIRECTORY = File.applicationStorageDirectory;
//how to create a loop frome here...
var pic_loader:Loader;
NetClassFactory.initialize( LocalCacheLoader, LocalCacheURLLoader, LocalCacheNetStream );
pic_loader = NetClassFactory.createLoader();
pic_loader.contentLoaderInfo.addEventListener( Event.COMPLETE, _onComplete );
var currentImageCount:uint = 1;
//load the first image
loadImage();
function loadImage():void
{
var pic_string:String = "http://localhost/Pics/" + String(currentImageCount) + ".jpg";
pic_loader.load( new URLRequest(pic_string));
}
function _onComplete(e:Event):void
{
var new_pic_mc:Sprite= new Sprite();
new_pic_mc.addChild(pic_loader);
new_pic_mc.width = new_pic_mc.height = 90;
this["ads_box_" + currentImageCount].photo_box.addChild(new_pic_mc);
this["ads_box_" + currentImageCount].photo_box.alpha = 1;
//WRITE YOUR CACHING LOGIC HERE FOR EACH LOADED IMAGE
if (currentImageCount <= 100)
{
currentImageCount++;
loadImage();
}
else
{
pic_loader.contentLoaderInfo.removeEventListener( Event.COMPLETE, _onComplete);
}
}
Hope this answers your question.
and finally this code works nice,thanks #Gurtej Singh
import org.sgmnt.lib.net.*;
import flash.net.URLRequest;
import flash.filesystem.File;
for (var i:Number=1; i<=5; i++)
{
this["ads_box_" + i].photo_box.alpha = 0;
}
LocalCacheSettings.WORKING_DIRECTORY = File.applicationStorageDirectory;
var currentImageCount:uint = 1;
var pic_loader:Loader;
loadImage();
function loadImage():void
{
NetClassFactory.initialize( LocalCacheLoader, LocalCacheURLLoader, LocalCacheNetStream );
pic_loader = NetClassFactory.createLoader();
pic_loader.contentLoaderInfo.addEventListener( Event.COMPLETE, _onComplete );
var pic_string:String = "http://localhost/Pics/" + String(currentImageCount) + ".jpg";
pic_loader.load( new URLRequest(pic_string));
}
function _onComplete(e:Event):void
{
var new_pic_mc:Sprite= new Sprite();
new_pic_mc.addChild(pic_loader);
new_pic_mc.width = new_pic_mc.height = 90;
this["ads_box_" + currentImageCount].photo_box.addChild(new_pic_mc);
this["ads_box_" + currentImageCount].photo_box.alpha = 1;
pic_loader.contentLoaderInfo.removeEventListener( Event.COMPLETE, _onComplete );
if (currentImageCount < 5)
{
currentImageCount++;
loadImage();
}
else
{
pic_loader.contentLoaderInfo.removeEventListener( Event.COMPLETE, _onComplete);
}
}

How do i select a specific part of an array or Vector when MouseEvent clicked?

Hi i am new to AS3 just couple of months into OOP i am not sure how do i select a specific part of an array or Vector when MouseEvent clicked.
So i parsed a list of Vector into this class called SearchVectorTest , and they are put into containers, i am trying to select the specific part of the Vector(which is text) when a specific container(box)that contain that part of the text is clicked. So that i can parse it to the next class file for further use.
At the moment i only have some idea about how to get the index of the part clicked which is below but it doesnt work.
var clickedpart:listings = Holder.target as Listing8;
var listIndex:uint = listings.indexOf(clickedpart);
trace("You clicked the part at index " + listIndex);
and i just tried this trace( bf.text+bf1.text+ bf2.text+bf3.text);
and it trace the last 4 text correctly, but not the one that i clicked.
This is the fullset of the SearchVectorTest
package com.clark
{
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class SearchVectorTest extends MovieClip
{
public var listings:Vector.<Listing8>;
public var _contentHolder: Sprite;
public function SearchVectorTest(test:Vector.<searchVO1>)
{
for (var j:int = 0; j < test.length; j++)
{
trace(test[j].nobed);
trace(test[j].zip);
trace(test[j].Location);
trace(test[j].price);
}
var james:int = test ? test.length : 0;
listings = new Vector.<Listing8>(james, true);
var currentY:int = 100;
for (var k:int = 0; k < test.length; k++)
{
var Bolder:Listing8 = new Listing8();
Bolder.x=20;
var bf:TextField = new TextField();
var bf1:TextField = new TextField();
var bf2:TextField = new TextField();
var bf3:TextField = new TextField();
bf3.width = 100;
bf.defaultTextFormat = new TextFormat("Arial", 12, 0, null, null, null, null, null, TextFormatAlign.CENTER);
bf.width = 100;
bf.autoSize = TextFieldAutoSize.CENTER;
bf1.width = 100;
bf1.autoSize = TextFieldAutoSize.CENTER;
bf2.autoSize = TextFieldAutoSize.CENTER;
bf3.autoSize = TextFieldAutoSize.CENTER;
bf3.width = 100;
bf1.y= bf.height+5;
// Pulling the textfields content out from the current bookVO
bf.text = test[k].nobed;
bf1.text = test[k].zip;
bf2.text = test[k].Location;
bf3.text = test[k].price;
bf.x = (Bolder.height-bf.height)*.2
Bolder.addChild(bf);
Bolder.addChild(bf1);
Bolder.addChild(bf2);
Bolder.addChild(bf3);
Bolder.properties = test[k].nobed;
Bolder.properties = test[k].zip;
// position the object based on the accumulating variable.
Bolder.y = currentY;
addChild(Bolder);
Bolder.mouseChildren = false; // ignore children mouseEvents
Bolder.mouseEnabled = true; // enable mouse on the object - normally set to true by default
Bolder.useHandCursor = true; // add hand cursor on mouse over
Bolder.buttonMode = true;
listings[k] = Bolder;
currentY += Bolder.height + 10;
}
if( listings.length > 0 )
{
_contentHolder = new Sprite();
addChild(_contentHolder);
for (var j:int = 0; j < listings.length; j++) {
_contentHolder.addChild(listings[j]);
}
_contentHolder.addEventListener(MouseEvent.CLICK, gotoscene);
}
function gotoscene(e: MouseEvent):void{
var clickedpart:Listing8 = Bolder.target as Listing8;
var listIndex:uint = listings.indexOf(clickedpart);
trace( bf.text+bf1.text+ bf2.text+bf3.text);
while(_contentHolder.numChildren > 0)
{
_contentHolder.removeChildAt(0);
}
while(GLOBALS.resultholder.numChildren > 0)
{
GLOBALS.resultholder.removeChildren();
}
var s5:Listingdetail= new Listingdetail ();
addChild(s5);
}
}
}
}
Thanks for your time
function gotoscene(e: MouseEvent):void{
var searchString = listings;
var index:Number;
index = searchString.indexOf(e.target);
trace(test[index].nobed+test[index].zip+test[index].Location+test[index].price);
}

Actionscript 3.0 form wiith user inputs and calculated fields saves empty as a PDF using AlivePDF

I've created a form that has lines, static text, and textFields in Flash Professional CS5.5, and using Actionscript 3.0 created fields that accepts a user's inputs and then calculates those user inputs and stores them in fields the user cannot edit. I need to print the filled-in form as a PDF and am using AlivePDF for this. The script creates the PDF but it is blank. How to I capture the entire stage as a PDF?
Here's the code in the .as file.
package {
// Flash imports
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.SimpleButton;
import flash.text.*;
import fl.controls.CheckBox;
import fl.accessibility.CheckBoxAccImpl;
import fl.controls.Button;
import flash.filesystem.File;
import flash.filesystem.FileStream;
import flash.net.FileReference;
import flash.net.FileReferenceList;
//import flash.display.Sprite;
import flash.media.CameraRoll;
import flash.display.StageScaleMode;
import flash.media.MediaPromise;
import flash.events.MediaEvent;
import flash.events.Event;
//AlivePDF imports
import org.alivepdf.pdf.PDF;
import org.alivepdf.layout.Orientation
import org.alivepdf.layout.Size;
import org.alivepdf.layout.Unit;
import org.alivepdf.display.Display
import org.alivepdf.saving.Method;
import org.alivepdf.fonts.FontFamily;
import org.alivepdf.fonts.Style;
import org.alivepdf.colors.RGBColor;
import org.alivepdf.images.ImageFormat;
import org.alivepdf.saving.Download;
import org.alivepdf.layout.Layout;
public class mfDataCollection extends MovieClip {
public function mfDataCollection() {
init();
}
private function init():void {
CheckBoxAccImpl.enableAccessibility();
stage.focus = testDate;
focusRect = testDate;
testDate.tabIndex = 1;
outsideTemp.tabIndex = 2;
buildingNumber.tabIndex = 3;
unitNumber.tabIndex = 4;
CAZ1AmbientCO.tabIndex = 5;
CAZ1Doors.tabIndex = 6;
CAZ1Fireplace.tabIndex = 7;
CAZ1CombustionAppliances.tabIndex = 8;
CAZ1Baseline.tabIndex = 9;
CAZ1Baseline.restrict = "-9-9";
CAZ1Dryer.tabIndex = 10;
CAZ1Dryer.restrict = "-9-9";
CAZ1CheckUnderDoors.tabIndex = 11;
CAZ1CheckUnderDoors.restrict = "-9-9";
CAZ1AirHandler.tabIndex = 12;
CAZ1AirHandler.restrict = "-9-9";
CAZ1RecheckPressure.tabIndex = 13;
CAZ1RecheckPressure.restrict = "-9-9";
CAZ1SetToWC.tabIndex = 14;
CAZ1WC.tabIndex = 15;
CAZ1BaselineCopy.tabIndex = 15;
CAZ1WCD.tabIndex = 16;
CAZ1DepressurizationLimitsPassed.tabIndex = 17;
CAZ1Monoxer.tabIndex = 18;
CAZ1App1SmallestBTU.tabIndex = 19;
CAZ1App1SpilliagePassed.tabIndex = 20;
CAZ1App1AmbientCO2.tabIndex = 21;
CAZ1App1AmbientCO2.restrict = "-9-9";
CAZ1App1Draft.tabIndex = 22;
CAZ1App1Draft.restrict = "-9-9";
CAZ1App1DraftPassed.tabIndex = 23;
CAZ1App1SpillageFailed.tabIndex = 24;
CAZ1App1UndilutedCO.tabIndex = 25;
CAZ1App1UndilutedCO.restrict = "-9-9";
CAZ1App1ActionLevelsPassed.tabIndex = 26;
CAZ1CompleteApp2.tabIndex = 27;
CAZ1App2TestRequired.tabIndex = 28;
ResetHousetoNormal.tabIndex = 29;
OvenCO.tabIndex = 30;
OvenCO.restrict = "0-9";
LeftRearBurner.tabIndex = 31;
LeftRearBurner.restrict = "0-9";
LeftFrontBurner.tabIndex = 32;
LeftFrontBurner.restrict = "0-9";
RightFrontBurner.tabIndex = 33;
RightFrontBurner.restrict = "0-9";
RightRearBurner.tabIndex = 34;
RightRearBurner.restrict = "0-9";
RightFrontBurner.tabIndex = 35;
CAZ1Dimensions.tabIndex = 36;
CAZ2Dimensions.tabIndex = 37;
GasLeakTestingPassed.tabIndex = 38;
Notes.tabIndex = 39;
IOUWorkOrder.tabIndex = 40;
// Setup handlers for mouse clicks
CAZ1Dryer.addEventListener(MouseEvent.CLICK, handleMouseClicks);
CAZ1CheckUnderDoors.addEventListener(MouseEvent.CLICK, handleMouseClicks);
CAZ1AirHandler.addEventListener(MouseEvent.CLICK, handleMouseClicks);
CAZ1RecheckPressure.addEventListener(MouseEvent.CLICK, handleMouseClicks);
CAZ1WC.addEventListener(MouseEvent.CLICK, handleMouseClicks);
CAZ1BaselineCopy.addEventListener(MouseEvent.CLICK, handleMouseClicks);
CAZ1WCD.addEventListener(MouseEvent.CLICK, handleMouseClicks);
}
private function handleMouseClicks(event:MouseEvent):void {
var numCAZ1Baseline:Number = Number(CAZ1Baseline.text);
var numCAZ1Dryer:Number = Number(CAZ1Dryer.text);
var numCAZ1CheckUnderDoors:Number = Number(CAZ1CheckUnderDoors.text);
var numCAZ1AirHandler:Number = Number(CAZ1AirHandler.text);
var numCAZ1RecheckPressure:Number = Number(CAZ1RecheckPressure.text);
var numCAZ1WC:Number = Number(CAZ1WC.text);
var numCAZ1BaselineCopy:Number = numCAZ1Baseline;
numCAZ1WC = Math.min(numCAZ1Dryer, numCAZ1CheckUnderDoors, numCAZ1AirHandler, numCAZ1RecheckPressure);
CAZ1WC.text = String(numCAZ1WC);
CAZ1BaselineCopy.text = String(numCAZ1BaselineCopy);
var numCAZ1WCD:Number = Number(CAZ1WCD.text);
numCAZ1WCD = numCAZ1WC - numCAZ1Baseline;
CAZ1WCD.text = numCAZ1WCD.toFixed(1);
}
private function handleButtonClicks(event:MouseEvent):void {
trace("You have clicked: " + event.currentTarget.name);
var filename:String; // = "CAZ_Bldg-" + buildingNumber.text + "-" + unitNumber.text + ".pdf";
var myPDF:PDF;
switch (event.currentTarget.name) {
case "btnSaveAsFileButton":
exportPDF();
break;
default:
trace("You clicked something else");
}
}
public function exportPDF() : void {
var filename:String = "CAZ_Bldg-" + buildingNumber.text + "-" + unitNumber.text + ".pdf";
trace("You are saving " + filename);
var myPDF = new PDF(Orientation.PORTRAIT, Unit.INCHES, Size.A4);
myPDF.setDisplayMode (Display.FULL_PAGE, Layout.SINGLE_PAGE);
myPDF.addPage();
var f:FileStream = new FileStream();
var file:File = File.userDirectory.resolvePath( filename );
f.open( file, FileMode.WRITE);
var bytes:ByteArray = myPDF.save(Method.LOCAL);
f.writeBytes(bytes);
f.close();
}
} // End of mfDataCollecion class
} // End of package

Detect when the Shader is done mixing the audio

so this the code with it i am able to mix several tracks
with a Shader done in pixel bender.
the problem here i don't know when the mixing is finish or all the sound reache their end
to be able to save the bytearray into a file any Event or something like that
help plz ?
package
{
import flash.display.*;
import flash.media.*;
import flash.events.*;
import flash.net.*;
import flash.utils.*;
import fl.controls.Slider;
import org.bytearray.micrecorder.encoder.WaveEncoder;
[SWF(width='500', height='380', frameRate='24')]
public class AudioMixer extends Sprite{
[Embed(source = "sound2.mp3")] private var Track1:Class;
[Embed(source = "sound1.mp3")] private var Track2:Class;
[Embed(source = "mix.pbj",mimeType = "application/octet-stream")]
private var EmbedShader:Class;
private var shader:Shader = new Shader(new EmbedShader());
private var sound:Vector.<Sound> = new Vector.<Sound>();
private var bytes:Vector.<ByteArray> = new Vector.<ByteArray>();
private var sliders:Vector.<Slider> = new Vector.<Slider>();
private var graph:Vector.<Shape> = new Vector.<Shape>();
private var recBA:ByteArray = new ByteArray();
private var BUFFER_SIZE:int = 0x800;
public var playback:Sound = new Sound();
public var container:Sprite = new Sprite();
public var isEvent:Boolean = false;
public function AudioMixer():void{
container.y = stage.stageHeight * .5;
addChild(container);
sound.push(new Track1(), new Track2(),new Track2(),new Track2(),new Track2(),new Track2(),new Track2(),new Track2(),new Track2(),new Track2(),new Track2(),new Track2());
for(var i:int = 0; i < sound.length; i++){
var slider:Slider = new Slider();
slider.maximum = 1;
slider.minimum = 0;
slider.snapInterval = 0.025;
slider.value = 0.8;
slider.rotation += -90;
slider.x = i * 40 + 25;
container.addChild(slider);
sliders.push(slider);
var line:Shape = new Shape();
line.graphics.lineStyle(1, 0x888888);
line.graphics.drawRect(i * 40 + 14, 0, 5, -80);
line.graphics.endFill();
container.addChild(line);
var shape:Shape = new Shape();
shape.graphics.beginFill(0x00cc00);
shape.graphics.drawRect(i * 40 + 15, 0, 3, -80);
shape.graphics.endFill();
container.addChild(shape);
graph.push(shape);
}
playback.addEventListener(SampleDataEvent.SAMPLE_DATA, onSoundData);
playback.play();
}
private function onSoundData(event:SampleDataEvent):void {
for(var i:int = 0; i < sound.length; i++){
bytes[i] = new ByteArray();
bytes[i].length = BUFFER_SIZE * 4 * 2;
sound[i].extract(bytes[i], BUFFER_SIZE);
var volume:Number = 0;
bytes[i].position = 0;
for(var j:int = 0; j < BUFFER_SIZE; j++){
volume += Math.abs(bytes[i].readFloat());
volume += Math.abs(bytes[i].readFloat());
}
volume = (volume / (BUFFER_SIZE * .5)) * sliders[i].value;
shader.data['track' + (i + 1)].width = BUFFER_SIZE / 1024;
shader.data['track' + (i + 1)].height = 512;
shader.data['track' + (i + 1)].input = bytes[i];
shader.data['vol' + (i + 1)].value = [sliders[i].value];
graph[i].scaleY = volume;
}
var shaderJob:ShaderJob = new ShaderJob(shader,event.data,BUFFER_SIZE / 1024,512);
shaderJob.start(true);
var shaderJob2:ShaderJob = new ShaderJob(shader,recBA,BUFFER_SIZE / 1024,512);
shaderJob2.start(true);
}
}
}
You can tell when a shader has completed it's job using the ShaderEvent.COMPLETE listener. Like so:
shaderJob.addEventListener(ShaderEvent.COMPLETE, onShaderComplete);
private function onShaderComplete(e:Event):void
{
//Do Something here
}
See this link for more details.
One thing about your code though. You're doing this shader job inside of a sampleDataEvent and I can see this being problematic (possibly) in the sense that your mixing may be out of sync with your playback (that is, if you plan on mixing live and writing the mixed data back into the sound stream). Anyway that's perhaps an issue for a new question. This should solve your problem with needing to know when the mixing is complete.
Note you also need to add "false" to the shaderJob.start(false) function. From the documentation about the ShaderEvent.COMPLETE:
"Dispatched when a ShaderJob that executes asynchronously finishes processing the data using the shader. A ShaderJob instance executes asynchronously when the start() method is called with a false value for the waitForCompletion parameter."
Update
In response to your inquiry about how to only process inside the sampleDataEvent if the sound isnt being processed:
private var isProcessing:Boolean = false;
private function onSoundData(event:SampleDataEvent):void {
if(isProcessing != true){
for(var i:int = 0; i < sound.length; i++){
bytes[i] = new ByteArray();
bytes[i].length = BUFFER_SIZE * 4 * 2;
sound[i].extract(bytes[i], BUFFER_SIZE);
var volume:Number = 0;
bytes[i].position = 0;
for(var j:int = 0; j < BUFFER_SIZE; j++){
volume += Math.abs(bytes[i].readFloat());
volume += Math.abs(bytes[i].readFloat());
}
volume = (volume / (BUFFER_SIZE * .5)) * sliders[i].value;
shader.data['track' + (i + 1)].width = BUFFER_SIZE / 1024;
shader.data['track' + (i + 1)].height = 512;
shader.data['track' + (i + 1)].input = bytes[i];
shader.data['vol' + (i + 1)].value = [sliders[i].value];
graph[i].scaleY = volume;
}
var shaderJob:ShaderJob = new ShaderJob(shader,event.data,BUFFER_SIZE / 1024,512);
shaderJob.start(false);
shaderJob.addEventListener(ShaderEvent.COMPLETE, onShaderComplete);
var shaderJob2:ShaderJob = new ShaderJob(shader,recBA,BUFFER_SIZE / 1024,512);
shaderJob2.start(false);
}
}
private function onShaderComplete(e:ShaderEvent):void
{
//Do something here
isProcessing = false;
}

doubt regarding carrying data in custom events using actionscript

I am working on actionscript to generate a SWF dynamically using JSON data coming from an HTTP request. I receive the data on creationComplete and try to generate a tree like structure. I don’t create the whole tree at the same time. I create 2 levels, level 1 and level 2. My goal is to attach custom events on the panels which represent tree nodes. When users click the panels, it dispatches custom events and try to generate the next level. So, it goes like this :
On creation complete -> get JSON-> create top tow levels -> click on level 2-> create the level 2 and level 3 -> click on level 3-> create level 3 and 4. …and so on and so on. I am attaching my code with this email. Please take a look at it and if you have any hints on how you would do this if you need to paint a tree having total level number = “n” where n = 0 to 100
Should I carry the data around in CustomPageClickEvent class.
[code]
import com.iwobanas.effects.*;
import flash.events.MouseEvent;
import flash.filters.BitmapFilterQuality;
import flash.filters.BitmapFilterType;
import flash.filters.GradientGlowFilter;
import mx.controls.Alert;
private var roundedMask:Sprite;
private var panel:NewPanel;
public var oldPanelIds:Array = new Array();
public var pages:Array = new Array();
public var delPages:Array = new Array();
public function DrawPlaybook(pos:Number,title:String,chld:Object):void {
panel = new NewPanel(chld);
panel.title = title;
panel.name=title;
panel.width = 100;
panel.height = 80;
panel.x=pos+5;
panel.y=40;
var gradientGlow:GradientGlowFilter = new GradientGlowFilter();
gradientGlow.distance = 0;
gradientGlow.angle = 45;
gradientGlow.colors = [0xFFFFF0, 0xFFFFFF];
gradientGlow.alphas = [0, 1];
gradientGlow.ratios = [0, 255];
gradientGlow.blurX = 10;
gradientGlow.blurY = 10;
gradientGlow.strength = 2;
gradientGlow.quality = BitmapFilterQuality.HIGH;
gradientGlow.type = BitmapFilterType.OUTER;
panel.filters =[gradientGlow];
this.rawChildren.addChild(panel);
pages.push(panel);
panel.addEventListener(MouseEvent.CLICK,
function(e:MouseEvent){onClickHandler(e,title,chld)});
this.addEventListener(CustomPageClickEvent.PANEL_CLICKED,
function(e:CustomPageClickEvent){onCustomPanelClicked(e,title)});
}
public function onClickHandler(e:MouseEvent,title:String,chld:Object):void {
for each(var stp1:NewPanel in pages){
if(stp1.title==title){
var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked");
eventObj.panelClicked = stp1;
dispatchEvent(eventObj);
}
}
}
private function onCustomPanelClicked(e:CustomPageClickEvent,title:String):void {
Alert.show("onCustomPanelClicked" + title);
var panel:NewPanel;
for each(var stp:NewPanel in pages){
startAnimation(e,stp);
}
if(title == e.panelClicked.title){
panel = new NewPanel(null);
panel.title = title;
panel.name=title;
panel.width = 150;
panel.height = 80;
panel.x=100;
panel.y=40;
this.rawChildren.addChild(panel);
var slideRight:SlideRight = new SlideRight();
slideRight.target=panel;
slideRight.duration=750;
slideRight.showTarget=true;
slideRight.play();
var jsonData = this.map.getValue(title);
var posX:Number = 50;
var posY:Number = 175;
for each ( var pnl:NewPanel in pages){
pages.pop();
}
for each ( var stp1:Object in jsonData.children){
panel = new NewPanel(null);
panel.title = stp1.text;
panel.name=stp1.id;
panel.width = 100;
panel.id=stp1.id;
panel.height = 80;
panel.x = posX;
panel.y=posY;
posX+=150;
var s:String="hi" + stp1.text;
panel.addEventListener(MouseEvent.CLICK,
function(e:MouseEvent){onChildClick(e,s);});
this.addEventListener(CustomPageClickEvent.PANEL_CLICKED,
function(e:CustomPageClickEvent){onCustomPnlClicked(e)});
this.rawChildren.addChild(panel);
pages.push(panel);
this.addEventListener(CustomPageClickEvent.PANEL_CLICKED,
function(e:CustomPageClickEvent){onCustomPanelClicked(e,title)});
var slide:SlideUp = new SlideUp();
slide.target=panel;
slide.duration=1500;
slide.showTarget=false;
slide.play();
}
}
}
public function onChildClick(e:MouseEvent,s:String):void {
for each(var stp1:NewPanel in pages){
if(stp1.title==e.currentTarget.title){
var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked");
eventObj.panelClicked = stp1;
dispatchEvent(eventObj);
}
}
}
private function onCustomPnlClicked(e:CustomPageClickEvent):void {
for each ( var pnl:NewPanel in pages){
pages.pop();
}
}
private function fadePanel(event:Event,panel:NewPanel):void{
panel.alpha -= .005;
if (panel.alpha <= 0){
panel.removeEventListener(Event.ENTER_FRAME,
function(e:Event){fadePanel(e,panel);});
};
panel.title="";
}
private function startAnimation(event:CustomPageClickEvent,panel:NewPanel):void{
panel.addEventListener(Event.ENTER_FRAME,
function(e:Event){fadePanel(e,panel)});
}
[/code]
Thanks in advance.
Palash
completely forgot i don't have enough rep to edit...
import com.iwobanas.effects.*;
import flash.events.MouseEvent;
import flash.filters.BitmapFilterQuality;
import flash.filters.BitmapFilterType;
import flash.filters.GradientGlowFilter;
import mx.controls.Alert;
private var roundedMask:Sprite;
private var panel:NewPanel;
public var oldPanelIds:Array = new Array();
public var pages:Array = new Array();
public var delPages:Array = new Array();
public function DrawPlaybook(pos:Number,title:String,chld:Object):void {
panel = new NewPanel(chld);
panel.title = title;
panel.name=title;
panel.width = 100;
panel.height = 80;
panel.x=pos+5;
panel.y=40;
var gradientGlow:GradientGlowFilter = new GradientGlowFilter();
gradientGlow.distance = 0;
gradientGlow.angle = 45;
gradientGlow.colors = [0xFFFFF0, 0xFFFFFF];
gradientGlow.alphas = [0, 1];
gradientGlow.ratios = [0, 255];
gradientGlow.blurX = 10;
gradientGlow.blurY = 10;
gradientGlow.strength = 2;
gradientGlow.quality = BitmapFilterQuality.HIGH;
gradientGlow.type = BitmapFilterType.OUTER;
panel.filters = [gradientGlow];
this.rawChildren.addChild(panel);
pages.push(panel);
panel.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){onClickHandler(e,title,chld)});
this.addEventListener(CustomPageClickEvent.PANEL_CLICKED, function(e:CustomPageClickEvent){onCustomPanelClicked(e,title)});
}
public function onClickHandler(e:MouseEvent,title:String,chld:Object):void {
for each(var stp1:NewPanel in pages){
if(stp1.title==title){
var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked");
eventObj.panelClicked = stp1;
dispatchEvent(eventObj);
}
}
}
private function onCustomPanelClicked(e:CustomPageClickEvent,title:String):void {
Alert.show("onCustomPanelClicked" + title);
var panel:NewPanel;
for each(var stp:NewPanel in pages){
startAnimation(e,stp);
}
if(title == e.panelClicked.title){
panel = new NewPanel(null);
panel.title = title;
panel.name=title;
panel.width = 150;
panel.height = 80;
panel.x=100;
panel.y=40;
this.rawChildren.addChild(panel);
var slideRight:SlideRight = new SlideRight();
slideRight.target=panel;
slideRight.duration=750;
slideRight.showTarget=true;
slideRight.play();
var jsonData = this.map.getValue(title);
var posX:Number = 50;
var posY:Number = 175;
for each ( var pnl:NewPanel in pages){
pages.pop();
}
for each ( var stp1:Object in jsonData.children){
panel = new NewPanel(null);
panel.title = stp1.text;
panel.name=stp1.id;
panel.width = 100;
panel.id=stp1.id;
panel.height = 80;
panel.x = posX;
panel.y=posY;
posX += 150;
var s:String="hi" + stp1.text;
panel.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){onChildClick(e,s);});
this.addEventListener(CustomPageClickEvent.PANEL_CLICKED, function(e:CustomPageClickEvent){onCustomPnlClicked(e)});
this.rawChildren.addChild(panel);
pages.push(panel);
this.addEventListener(CustomPageClickEvent.PANEL_CLICKED, function(e:CustomPageClickEvent){onCustomPanelClicked(e,title)});
var slide:SlideUp = new SlideUp();
slide.target=panel;
slide.duration=1500;
slide.showTarget=false;
slide.play();
}
}
}
public function onChildClick(e:MouseEvent,s:String):void {
for each(var stp1:NewPanel in pages){
if(stp1.title==e.currentTarget.title){
var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked");
eventObj.panelClicked = stp1;
dispatchEvent(eventObj);
}
}
}
private function onCustomPnlClicked(e:CustomPageClickEvent):void {
for each ( var pnl:NewPanel in pages){
pages.pop();
}
}
private function fadePanel(event:Event,panel:NewPanel):void{
panel.alpha -= .005;
if (panel.alpha <= 0){
panel.removeEventListener(Event.ENTER_FRAME,
function(e:Event){fadePanel(e,panel);});
};
panel.title="";
}
private function startAnimation(event:CustomPageClickEvent,panel:NewPanel):void{
panel.addEventListener(Event.ENTER_FRAME,
function(e:Event){fadePanel(e,panel)});
}