Could someone check out the way the object are created? All the classes work independently but somewhere I think I am messing the display up when I call a new Class.
I have two classes: one creates and loades a combobox and another class that creates and
loads an UILoader .
They both work fie independently.
In these classes below If I have the fileName and the Key in the UILoader class hard coded
all the Components and the Images display.
However, If I send the fileName and the Key from the CBMaorComponent class (cbMajor
Combobox )
when the selection is made there is no display.
The code traces that the UILoader is loaded with the proper URL's from the XML but no
Images show up on the mcContent(movieClip).
This is in the actions frame in the .fla
import flash.display.MovieClip;
import chromatic.load_files.UIImageComponent;
import chromatic.load_files.TLImageComponent;
import chromatic.load_files.CBMajorComponent;
import chromatic.load_files.CBMinorComponent;
var uiImageComponent:UIImageComponent=new UIImageComponent();
var tlImageComponent:TLImageComponent=new TLImageComponent();
var cbMajorComponent:CBMajorComponent=new CBMajorComponent();
var cbMinorComponent:CBMinorComponent=new CBMinorComponent();
cbMajorComponent=new CBMajorComponent();
addChild(cbMajorComponent.cbMajor);
cbMinorComponent=new CBMinorComponent();
addChild(cbMinorComponent.cbMinor);
uiImageComponent=new UIImageComponent();
mcContent.addChild(uiImageComponent.uiImage);
tlImageComponent=new TLImageComponent();
mcContent.addChild(tlImageComponent.tlImage);
This is the UILoader class and it displays an image if I hard code the fileName and key
needed to get the URL from the XML.
but when I send it parameters from the CBMajorComponent class (combobox) it gets the
proper fileName and key variables but it will not display.
package chromatic.load_files{
import fl.containers.UILoader;
import flash.display.MovieClip;
import flash.events.Event;
import fl.data.DataProvider;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.*;
public class UIImageComponent extends MovieClip {
public var uiImage:UILoader=new UILoader();
public var dp:DataProvider=new DataProvider();
private var dataLoader:URLLoader=new URLLoader();
private var theXML:XML=new XML();
private var listURL:URLRequest=new URLRequest();
private var arrayImage:Array=new Array();
private var singleImage:String;
public var key:String;
public var fileName:String;
private var sourceValue:String=null;
private var evtIndex:int;
private var evtName:String;
private var sel:Number=-1;
private var xmlList:XMLList;
public function UIImageComponent():void {
}
public function init(fileName,key):void {
this.fileName=fileName;
this.key=key;
setFileName(fileName);
setKey(key);
setupComponent(); }
public function setupComponent():void{
uiImage.x=100;
uiImage.y=-20;
uiImage.width=190;
uiImage.height=200;
listURL=new URLRequest(getFileName());
dataLoader.addEventListener(Event.COMPLETE,dataLoaded);
dataLoader.load(listURL);
theXML=new XML(listURL);
theXML.ignoreWhitespace=true;
}
function dataLoaded(evt:Event):void {
theXML=XML(dataLoader.data);
trace("///// in ui fileName= "+fileName+" //////////////////");
sourceValue=theXML.key[getKey()].swfFile;
var request:URLRequest=new URLRequest(sourceValue);
uiImage.load(request);
trace("///// in ui key= "+sourceValue+" //////////////////");
uiImage.source=sourceValue;
}
/*
private function selectedName():void {
}
*/
private function changeEvent(evt:Event):void {
trace(" You selected a key");
}
public function setFileName(fileName):void {
this.fileName=fileName;
}
public function getFileName():String {
return fileName;
}
public function setKey(key):void {
this.key=key;
}
public function getKey():String {
return key;
}
}
}
This is the class that laods the combobox and in the selectedName method it sends the
UIImageComponent class (UILoader) the fileName and the key when a selection is made.
And that class excepts it and
loads the source derived from the XML but again no display of the selection made.
package chromatic.load_files{
import fl.controls.ComboBox;
import flash.display.MovieClip;
import flash.events.Event;
import fl.data.DataProvider;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequest;
import fl.containers.UILoader;
public class CBMajorComponent extends MovieClip {
public var cbMajor:ComboBox=new ComboBox();
private var uiImageComponent:UIImageComponent;
private var listURL:URLRequest=new URLRequest();
private var dataLoader:URLLoader=new URLLoader();
private var theXML:XML=new XML();
private var arrayFile:Array=new Array("load_assets/keylist.xml");
private var majorArray:Array=new Array
("CMajor","GMajor","DMajor","AMajor","EMajor",
"BMajor","FSharpMajor","CSharpMajor","FMajor",
"BFlatMajor","EFlatMajor","AFlatMajor",
"DFlatMajor","GFlatMajor","CFlatMajor");
public var key:String;
public var fileName:String;
private var evtIndex:Number;
private var evtItem:String;
private var sel:Number=-1;
public function CBMajorComponent():void {
init();
}
private function init():void {
fileName=arrayFile[0];
setFileName(fileName);
setupComponent(fileName);
}
private function setupComponent(fileName):void {
this.fileName=fileName;
cbMajor=new ComboBox();
cbMajor.setSize(200, 22);
cbMajor.prompt = "Select a Major Key";
cbMajor.editable=false;
cbMajor.rowCount=15;
cbMajor.width=110;
cbMajor.move(0,0);
cbMajor.x=-235;
cbMajor.y=-150;
listURL=new URLRequest(fileName);
dataLoader.addEventListener(Event.COMPLETE,dataLoaded);
dataLoader.load(listURL);
theXML=new XML(listURL);
theXML.ignoreWhitespace=true;
cbMajor.addEventListener(Event.CHANGE, selectedName);
cbMajor.addEventListener(Event.CHANGE,changeEvent);
}
private function dataLoaded(evt:Event):void {
theXML=XML(dataLoader.data);
for (var i:int=0; i<majorArray.length; i++) {
key=majorArray[i];
cbMajor.addItem({label:(theXML.key[key].keyName)});
}
}
private function selectedName(evt:Event):void {
evtIndex=evt.target.selectedIndex;
key=majorArray[evtIndex];
setKey(key);
uiImageComponent=new UIImageComponent();
uiImageComponent.init(fileName,key);
}
public function changeEvent(evt:Event):void {
trace(" You selected a key");
}
public function setFileName(fileName):void {
this.fileName=fileName;
}
public function getFileName():String {
return fileName;
}
public function setKey(key):void {
this.key=key;
}
public function getKey():String {
return key;
}
}
}
Thank you for your time.
ceyesuma
I didn't want to make it really confusing yet It may be relavant to add that I have two
more classes
(all four work at the same independent of each other but no passing of args(parameters)
mind you.
These two classes are identical to the first two but the combobox when selectedItem calls
it's CHANGE event(selectedName).
it sends the same fileName and key var. to the TLImageComponent class
(note: the combo box selection is irrelevent in these classes no matter what the selection
is it's function is to solely send the fileName and key and tht tlImage always does the
same thing.tlImage is the TileBox()/for now.)
The ComboBox()
package chromatic.load_files{
import fl.controls.ComboBox;
import fl.controls.TileList;
import flash.display.MovieClip;
import flash.events.Event;
import fl.data.DataProvider;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequest;
import flash.utils.*;
import flash.events.TimerEvent;
import fl.containers.UILoader;
import chromatic.load_files.TLImageComponent;
public class CBMinorComponent extends MovieClip {
public var cbMinor:ComboBox=new ComboBox();
private var tlImageComponent:TLImageComponent;
private var listURL:URLRequest=new URLRequest();
private var dataLoader:URLLoader=new URLLoader();
private var theXML:XML=new XML();
private var arrayFile:Array=new Array("load_assets/keylist.xml");
/*
private var minorArray:Array=new Array
("aMinor","eMinor","bMinor","fSharpMinor",
"cSharpMinor","GSharpMinor","dSharpMinor","aSharpMinor","dMinor",
"gFlatMinor","cMinor","fMinor","bFlatMinor","eFlatMinor","aFlatMinor");
*/
private var majorArray:Array=new Array
("CMajor","GMajor","DMajor","AMajor","EMajor",
"BMajor","FSharpMajor","CSharpMajor","FMajor",
"BFlatMajor","EFlatMajor","AFlatMajor",
"DFlatMajor","GFlatMajor","CFlatMajor");
public var key:String;
public var fileName:String;
private var evtIndex:int;
private var evtName:String;
private var sel:Number=-1;
public var testString:String;
public function CBMinorComponent():void {
init();
}
private function init():void {
fileName=arrayFile[0];
setFileName(fileName);
setupComponent();
}
public function setupComponent():void {
cbMinor=new ComboBox();
cbMinor.setSize(200, 22);
cbMinor.prompt = "Select a Minor Key";
cbMinor.editable=false;
cbMinor.rowCount=15;
cbMinor.width=110;
cbMinor.move(0,0);
cbMinor.x=-235;
cbMinor.y=-120;
addChild(cbMinor);
theXML=new XML(fileName);
theXML.ignoreWhitespace=true;
listURL=new URLRequest(theXML);
dataLoader=new URLLoader(listURL);
try {
dataLoader.load(listURL);
} catch (error:Error) {
trace("Unable to load requested document");
}
dataLoader.addEventListener(Event.COMPLETE,dataLoaded);
cbMinor.addEventListener(Event.CHANGE, selectedName);
cbMinor.addEventListener(Event.CHANGE,changeEvent);
}
public function dataLoaded(evt:Event):void {
theXML=XML(dataLoader.data);
for (var i:int=0; i<majorArray.length; i++) {
key=majorArray[i];
//var mcContent:MovieClip=new MovieClip();(theXML.key
[key].relative);
cbMinor.addItem({label:(theXML.key[key].relative)});
}
}
private function selectedName(evt:Event):void {
tlImageComponent=new TLImageComponent();
evtIndex=evt.target.selectedIndex;
key=majorArray[evtIndex];
testString="passed froim cbMinor to tlComponent";
tlImageComponent.init(fileName,key);
}
private function changeEvent(evt:Event):void {
trace(" You selected a key");
}
public function setFileName(fileName):void {
this.fileName=fileName;
}
public function getFileName():String {
return fileName;
}
public function setKey(key):void {
this.key=key;
}
public function getKey():String {
return key;
}
}
}
TileList()
package chromatic.load_files{
import fl.controls.TileList;
import flash.display.MovieClip;
import flash.events.Event;
import fl.data.DataProvider;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class TLImageComponent extends MovieClip {
public var tlImage:TileList=new TileList();
private var dp:DataProvider=new DataProvider();
private var dataLoader:URLLoader=new URLLoader();
public var theXML:XML=new XML();
private var listURL:URLRequest=new URLRequest();
private var arrayImage:Array=new Array();
private var majorArray:Array=new Array
("CMajor","GMajor","DMajor","AMajor","EMajor",
"BMajor","FSharpMajor","CSharpMajor","FMajor",
"BFlatMajor","EFlatMajor","AFlatMajor",
"DFlatMajor","GFlatMajor","CFlatMajor");
private var singleImage:String;
public var key:String;
public var fileName:String;
private var sourceValue:String=null;
private var evtIndex:int;
private var evtName:String;
private var sel:Number=-1;
public var testString:String;
public function TLImageComponent():void {
}
public function init(fileName,key):void {
//fileName="load_assets/keylist.xml";
//key="DMajor";
this.fileName=fileName;
this.key=key; // this var is irrelevant at present
setFileName(fileName);
setKey(key);
setupComponent();
}
public function setupComponent():void {
tlImage=new TileList();
tlImage.move(0,160);
tlImage.width=400;
tlImage.height=150;
tlImage.columnWidth=120;
tlImage.rowHeight=145;
listURL=new URLRequest(getFileName());
dataLoader.addEventListener(Event.COMPLETE,dataLoaded);
dataLoader.load(listURL);
theXML=new XML(listURL);
theXML.ignoreWhitespace=true;
}
private function dataLoaded(evt:Event):void {
trace("///// in tl fileName= "+fileName+" //////////////////");
theXML=XML(dataLoader.data);
arrayImage=new Array();
for (var i:int=0; i<15;i++) {
key=majorArray[i];
trace("///// in tl display each key= "+key+"
//////////////////");
var theImage:String=theXML.key[key].swfFile;
var request:URLRequest=new URLRequest(theImage);
arrayImage.push({source:theImage});
}
dp=new DataProvider(arrayImage);
tlImage.dataProvider=dp;
}
private function selectedName():void {
}
private function changeEvent(evt:Event):void {
trace(" You selected a key");
}
public function setFileName(fileName):void {
this.fileName=fileName;
}
public function getFileName():String {
return fileName;
}
public function setKey(key):void {
this.key=key;
}
public function getKey():String {
return key;
}
}
}