Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

out of my league with this one - xml and flash 1

Status
Not open for further replies.

whoknows361

Technical User
Sep 22, 2005
228
US
hello. I need some help.
goal: to have all data load from xml file into main mc "contentMain" and create individual mc's from the duplicated "item mc".
Basicaly, if you had a store, it would look like this:
|item, item, item,|
|item, item, item,|
|item, item, item,|
|item, item, item|

I am using code I adopted from kirupa's slideshow tutorial, however, I believe what I am trying to do, is outside of my current skills.
I want each xml node to present on the screen with the data for image, description, price to load into the "item" mc, which is duplicated for each node.
I can't figure out where I need to go from here and am getting nothing when I test it. Please tell me where I went wrong & what to do.

Any help would be appreciated. And please comment your code or provide some type of explanation as I want to learn from this & don't want to waste your time again.

Here is the fla, xml & jpg files:

Thanks in advance.
Jonathan
 
This needs a bit of tidying up:
[ul]
[li]Spelling mistakes - "contentmain" and "contentMain" are not the same at all[/li]
[li]You can't refer to the non existent object: "contentMain.t"+k - this should be contentMain["item"+k][/li]
[/ul]
There are few other things you need to change in order to accomplish your intension, but above are the crucial points and should let you get going.

Kenneth Kawamoto
 
Kenneth - and all.
Thanks for the input, & I have updated as you indicated. However, I have spent about 10 hours on this & still can't continue to fix the problem. the images load with their correct roll-over,roll-out functions, however, they do not load into the mc "item" as they are supposed to.

In face, the mc "item" only loads once, & the rest of the images simply load behind (they are spaced correctly & display correct roll over events,), but they do not load into multiple presentations of the "item" mc.

I am close on this & have tried multiple work-arounds, but fear that I am missing something basic, or am not understanding the flow of the code. Here is the updated example I have:

Please, I would really appreciate your follow-up advice on this. Thanks

Jonathan
 
This is not right:
Code:
partone = "contentMain.";
parttwo = "item" + k;
partthree = ".picture";
partfour = partone+parttwo+partthree;
image_mcl.loadClip(image[k], partfour);
Because you cannot load JPEGs into Strings!

You can do:
Code:
partone = "contentMain.";
parttwo = "item"+k;
partthree = ".picture";
partfour = partone+parttwo+partthree;
image_mcl.loadClip(image[k], eval(partfour));

But why not simply do:
Code:
image_mcl.loadClip(image[k], contentMain[itemname].picture);

After that you have to change the inside of "tlistener.onLoadInit = function(target_mc) {}" function, because "target_mc" refers to the MovieClip "itemX.picture" but you are treating it as MovieClip "itemX" in your code. Try "target_mc._parent" as this referes to "itemX".

Kenneth Kawamoto
 
kenneth, thanks so much for your input - after you indicated the path of "target_mc", I was able to understand what was going on & fixed much of my dilema.
I have been able to complete most of this task, but still have 2 areas of concern that could use your assistance.

If you check:
you will see my updated file & see that I am almost there!
but:
1) how do I get my individual "item" mc's to show my preloader. I have a preloader mc already ready to be used, but am not sure what the code would be, & where to put the code so that my preloader mc shows the load status of each "item" mc as they load.

2) I have included a custom scrollbar, however, when the movie is tested none of the buttons (up & down) work & the scrollFace itself does not even showup. I know that the scrollbar code is solid as I have used many times on other projects, but for some reason, it is not working with this. The scrollbar code is on frame 2. ?!

I would greatly appreciate your help on this & thank you for your previous posts as I am really getting to understand the nature of arrays.

Thanks so much for your help thus far.

Jonathan.
 
The beauty of MovieClipLoader class is it's very easy to monitor loading progress.

Add the following to your code:
Code:
tlistener.onLoadProgress = function(targetMC, loadedBytes, totalBytes) {
		trace(targetMC+": "+loadedBytes+"bytes of "+totalBytes+"bytes are loaded");
	};
You'll see the loading activities in Output. Your JPEGs are too small to see much of them though as they loads instantly.


Kenneth Kawamoto
 
Hey Kenneth,
Thanks for your previous post. I have been able to identify the problem & fix it & have everything that I need for this project except one thing: a usable scrollbar.
I have used a custom scrollbar code from kirupa, which I have used many times, but does not work with this.

I have tried to use the scrollPane component but this does not work (and I would rather not ie. the filesize).
also, I am using FlashMX2004, so no scrollbar component.

It seems that there are problems initating a scrollBar for a movieclip whose size changes dynamically dependant on the number of items in the xml file.

Please see:

as you will see my updates & fixes (ie. the loader component). Please help me identify a way to use a scrollbar, where should it be implemented (frame#), what code might work for this situation.

This is the last item I need to understand for both the completion of the project, and my own development of like projects in the future.

Thanks so much for you previous help.

Jonathan
 
This is bare minimal code to get you started:
Code:
function scrollBar() {
	this["scrollDirection"] = 0;
	this.attachMovie("upbutton", "upbutton", 1, {_x:560, _y:15});
	this.attachMovie("downbutton", "downbutton", 2, {_x:560, _y:370});
	upbutton.onPress = function() {
		this._parent.scrollDirection = 1;
	};
	downbutton.onPress = function() {
		this._parent.scrollDirection = -1;
	};
	upbutton.onRelease = downbutton.onRelease=function () {
		this._parent.scrollDirection = 0;
	};
	this.onEnterFrame = function() {
		contentMain._y += scrollDirection;
	};
}
Call this function from XML onLoad(success).

Kenneth Kawamoto
 
Kenneth, thanks so much for your help - i decided to give it a go and try to code my own scrollbar application.
It worked out quite well, however, I have one last question. I have gotten the up & down arrows to work. The scrollFace to work, but simply am missing the scrollface on drag data. I am not sure how to make the scrollFace reach the bottom at the same time content Main does. I will post my code & would appreciate any assistance. I know exactly where the code help I need should be placed & have commented as such. Here is the code: Any help would be appreciated by anyone:

//following is scrollBar code - change all "_root." to the path of this .swf if .swf is dynamically loaded//
scrollBar = function () {
initialy = _root.contentMain._y;
bottomy = -300; //this # needs to be hard-coded, dependent on the final y value of contentMain you want when you press the downbutton//
increment = 5; //number of units that content Main moves on either up or down arrow press//
units = (Math.abs(initialy - bottomy)) / increment; //used for further calculation;


_root.attachMovie("upbutton", "upbutton", 2004);
this.upbutton._x = 570;
this.upbutton._y = 55;

_root.attachMovie("downbutton", "downbutton", 2005);
this.downbutton._x = 570;
this.downbutton._y = 340;

_root.attachMovie("scrollTrack", "scrollTrack", 2002);
yvalue = this.upbutton._y + this.upbutton._height; //for getting y & height values
this.scrollTrack._width = this.upbutton._width - 4; //creating width - 4 smaller than buttons//
this.scrollTrack._x = this.upbutton._x + 2; //creating x location - centered on up button/
this.scrollTrack._y = yvalue; //creating y value = up button y + up button height.
this.scrollTrack._height = this.downbutton._y - yvalue; //the space between up & down buttons//

_root.attachMovie("scrollFace", "scrollFace", 2003);
this.scrollFace._x = this.scrollTrack._x + 1;
this.scrollFace._y = this.scrollTrack._y;
sfunits = this.scrollTrack._height - this.scrollFace._height;

//this variable is listed here becuase they hadn't been substantiated yet//
sfincrement = sfunits / units; //number of units that scrollFace moves on either up or down arrow press//

// up button code//
this.upbutton.onPress = function (){
this.onEnterFrame = function() {
if (_root.contentMain._y > initialy) {
donothing;}
else if (_root.contentMain._y < initialy) {
this._parent.contentMain._y = this._parent.contentMain._y + increment;
if(this._parent.scrollFace._y < this._parent.scrollTrack._y) {
donothing;}
else if(this._parent.scrollFace._y > this._parent.scrollTrack._y) {
this._parent.scrollFace._y = this._parent.scrollFace._y - sfincrement;
}}}}

this.upbutton.onRelease = function() { //so stops scrolling
delete this.onEnterFrame;}

this.upbutton.onDragOut = function() { //so stops scrolling
delete this.onEnterFrame;}

//down button code//
this.downbutton.onPress = function() {
this.onEnterFrame = function() {
if (_root.contentMain._y < bottomy) {
donothing; }
else if (_root.contentMain._y > bottomy) {
this._parent.contentMain._y = this._parent.contentMain._y - increment;
if(this._parent.scrollFace._y > this._parent.downbutton._y - this._parent.scrollFace._height) {
donothing;}
else if(this._parent.scrollFace._y < this._parent.downbutton._y - this._parent.scrollFace._height) {
this._parent.scrollFace._y = this._parent.scrollFace._y + sfincrement;
}}}}

this.downbutton.onRelease = function() { //so stops scrolling
delete this.onEnterFrame;}

this.downbutton.onDragOut = function() { //so stops scrolling
delete this.onEnterFrame;}

//scrollFace Drag Code//
this.scrollFace.onPress = function() {
var currPos:Number = this._y;
var top = this._parent.scrollTrack._y
var bottom = this._parent.downbutton._y - this._parent.scrollFace._height
startDrag(this, false, this._x, top, this._x, bottom);
this.onMouseMove = function() {
sfy = scrollFace._y;
cmy = contentMain._y;
//what code should be here so that I can drag the scrollFace to the bottom and
//contentMain will be at the bottom, etc.//

}
}

this.scrollFace.onMouseUp = function() {
stopDrag();
delete this.onMouseMove;
};
}
scrollBar();

Also, you can download at scrollbar code is on frame 2 in actions layer.

Thank so much for all previous help on this forum.
Jonathan
 
Again, thanks kenneth for all of your assistance. I will help others regarding what I have learned - from what I have learned from your assistance.'

Jonathan
 
Code:
this.onMouseMove = function() {
			//what code should be here so that I can drag the scrollFace to the bottom and
			//contentMain will be at the bottom, etc.//
			sfy = scrollFace._y;
			[b]contentMain._y = initialy+(sfy-yvalue)*(bottomy-initialy)/sfunits;
			updateAfterEvent();[/b]
		};

Kenneth Kawamoto
 
thats it! works like a charm. Thanks again Kenneth for your help on this project.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top