A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 26

Thread: [f8]

  1. #1
    Senior Designer
    Join Date
    Jul 2001
    Location
    Australia
    Posts
    367

    [f8]

    Hey there! I was wondering if someone could help me along with a code I've been working with for a game, it's a unit queue system which allows a user to select units and queue them up for creation.

    So far it works pretty well, the SWF is here for you to see:
    http://www.liquid-visual.com/panel6.html

    All you need to do is click one of the boxes to the left for them to queue on the right. The code I'm using is;

    Code:
    var currentBox = 1;
    function fillBox(labelName) {
    	_parent["box"+currentBox].gotoAndStop(labelName);
    	currentBox++;
    }
    adam.onRelease = function() {
    	fillBox("adam");
    	_parent.compiler.play();
    };
    eve.onRelease = function() {
    	fillBox("eve");
    	_parent.compiler.play();
    };
    spectre.onRelease = function() {
    	fillBox("spectre");
    	_parent.compiler.play();
    };
    What I'm trying to do now is shift the boxes up one space once a box is finished creating. I'm aiming to do this with the load bar.

    The idea is that inside the MC of the loading bar, at the end of the load (on the final frame) - if the first box's current frame equals a certain unit, that unit will place itself somewhere on the movie canvas..perhaps randomly, but that's further down the track.

    My QUESTION now is how would I go about making it so that after the loading bar finishes it's animation it clears box1 (frame 1 / label; "none") and the next box moves into its place, and so forth. ?

    So once box1 finishes, box2 moves into box1 and box3 moves into box2 etc etc

    A little more complicated, just hope it's possible!

    http://www.liquid-visual.com/panel5.fla I've uploaded the FLA if it makes it easier to see what I'm doing.

    Thanks!

  2. #2
    Senior Designer
    Join Date
    Jul 2001
    Location
    Australia
    Posts
    367
    I tried some commands like;

    Code:
    _parent.box3.gotoAndStop(_parent.box4._currentframe);
    _parent.box2.gotoAndStop(_parent.box3._currentframe);
    _parent.box1.gotoAndStop(_parent.box2._currentframe);
    
    (why are the 'E's spaced forward??)
    And also played around with some alt methods like x and y values, which got unnecessarily complicated. It just stuffs it up further, the boxes don't shift up a space correctly. Ultimately I need to be able to determine the next box's position, and switch the one infront to it, until the queue "appears" to have shifted. But also the problem is being able to queue when a box becomes 'available' in the correct space without getting a conflict. I'm desperate!

    Can't anyone please help me?



    By the way, sorry about the obscure title of this thread - for some reason what I typed didn't go through on enter!

  3. #3
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    Something like this?
    PHP Code:
    function fillBox () {
        
    _parent.box1.gotoAndStop (_parent.box2._currentframe);
        
    _parent.box2.gotoAndStop (_parent.box3._currentframe);
        
    _parent.box3.gotoAndStop (_parent.box4._currentframe);
        
    _parent.box4.gotoAndStop ("none");
    }
    fillBox (); 

  4. #4
    Senior Designer
    Join Date
    Jul 2001
    Location
    Australia
    Posts
    367
    It doesn't actually work, check out the swf:

    http://www.liquid-visual.com/panel8.html

    It just glitches and doesn't work properly. Is there a different way I should be approaching this?

    http://www.liquid-visual.com/panel8.html

  5. #5
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,379
    It sounds like what you need is a better queue system. I've written this quick (ok, like 2 hour) .fla so you can better see how a simple queue system works.
    Attached Files Attached Files
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  6. #6
    Senior Designer
    Join Date
    Jul 2001
    Location
    Australia
    Posts
    367
    Wow that works ridiculously well, very impressed! Only thing is I'm very basic at AS, all I can really do is basic functions and If statements. How would I apply such a code to my interface? It's a bit difficult for me to understand (even with the notes - much appreciated btw) as the code calls everything to the stage and I'm not great at working with things that I can't see. I feel lost

  7. #7
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,379
    look into attachMovie for the items themselves. Also, when I said that it was a "fancy" way to draw the compileBar, I meant I was too lazy to draw it manually, and I can usually draw basic stuff with Flash's Drawing API (also a good look, but a bit advanced for you at this point), instead it should just be premade. Sorry that everything is called to the stage. Personally I feel it's better practice to not have anything on the stage prior to runtime, as these things can't be as readily manipulated as dynamically created content.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  8. #8
    Senior Designer
    Join Date
    Jul 2001
    Location
    Australia
    Posts
    367
    Okay, I've been going through your code and I managed to edit it a little (from what I was able to understand) - I managed to replace the little symbols to the ones I'm using and changed the mouseclick to a specific button, so each button queues a different object, as below:

    Before Queue



    After Queue



    SWF

    http://www.liquid-visual.com/queueTest.html


    That's as far as I can get so far, i'm going to keep trying - but could you show me how to make the objects attach to the box1, box2, box3, box4 MCs to the right? So they attach themselves directly over them, covering them.

    Also with the loadbar, is it possible to integrate the compiler bar on the right? Like maybe it queues once the animation reaches its end frame? At least that way I can add animation effects etc to the load bar and understand better how to manipulate it.

    http://www.liquid-visual.com/queueTest.fla

    Thanks!

  9. #9
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,379
    yeah it's pretty simple. Give this a try. Modify my code to restict the queue to 4 items. Also, create another array like queueListCoords = [box1, box2, box3, box4], so that you can reference their x and y values. Change the shift function to, instead of moving them all to the left, do this:

    Code:
    for (i=0; i< queueList.length; i++) {
    queueList[i]._x = queueListCoords[i]._x;
    queueList[i]._y = queueListCoords[i]._y;
    }
    Using this method, you could potential create any shape of queue boxes. I can really describe right now how to change the compiler bar, but give all this a shot, and keep working on the compile progress bar. Should you not be able to get it done, I might be able to take a look at it tomorrow (monday) afternoon sometime.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  10. #10
    Senior Designer
    Join Date
    Jul 2001
    Location
    Australia
    Posts
    367
    I'll give it a go and post my progress, thanks!

  11. #11
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,818
    nevermind
    .

  12. #12
    Senior Designer
    Join Date
    Jul 2001
    Location
    Australia
    Posts
    367
    Okay I've managed to get this done now;

    Code:
    // run through the array of items and move them all over.
    queueListCoords = [box1, box2, box3, box4];
    //
    function shift() {
    	for (i=0; i<queueList.length; i++) {
    		queueList[i]._x = queueListCoords[i]._x;
    		queueList[i]._y = queueListCoords[i]._y;
    	}
    }
    It seems to queue them when they shift, just not when you attach them. I think I need a bit more help, I've never really written an array and I'm a beginner with adv actionscript.
    Last edited by Mitch Warren; 07-09-2007 at 03:56 AM.

  13. #13
    Senior Designer
    Join Date
    Jul 2001
    Location
    Australia
    Posts
    367
    Woo! After ages of tinkering I think i finally worked it out, this is the code now:

    Code:
    // vars in root for public use
    queueList = [];
    queueListCoords = [box1, box2, box3, box4];
    // Draws new content item;
    function enqueue(obj) {
    	// new item
    	var item = attachMovie("item", "item"+(queueList.length+1), getNextHighestDepth());
    	// place the item at the end of the queue
    	queueList.push(item);
    	// go to proper frame
    	item.gotoAndStop(obj.frame);
    	// set compile time
    	item.cTime = 30*obj.frame;
    	// save the frame info
    	item.frame = obj.frame;
    	// set it's proper coordinates
    	item._x = shift();
    	item._y = shift();
    	//
    	// and delete the object;
    	delete obj;
    }
    function newObj() {
    	var obj = new Object();
    	return obj;
    }
    // click to create objects;
    adam.onRelease = function() {
    	compiler.play();
    	// if it's not full
    	if (queueList.length<4) {
    		// create a new object
    		var obj = newObj();
    		obj.frame = 1;
    		// and enqueue it in the list
    		enqueue(obj);
    	}
    };
    // Eve Button //
    eve.onRelease = function() {
    	// if it's not full
    	if (queueList.length<4) {
    		// create a new object
    		var obj = newObj();
    		obj.frame = 2;
    		// and enqueue it in the list
    		enqueue(obj);
    	}
    };
    // Spectre Button //
    spectre.onRelease = function() {
    	// if it's not full
    	if (queueList.length<4) {
    		// create a new object
    		var obj = newObj();
    		obj.frame = 3;
    		// and enqueue it in the list
    		enqueue(obj);
    	}
    };
    // 
    onEnterFrame = function () {
    	// good practice to do this instead of coding in the onEnterFrame itself
    	compileNext();
    };
    function compileNext() {
    	// if there's items
    	if (queueList.length>0) {
    		// and it's not done
    		if (queueList[0].cTime>0) {
    			// reduce the time left
    			queueList[0].cTime--;
    			// and update the progress bar
    		} else {
    			// order matters here;
    			// record name of first element for message
    			var shifted = queueList[0];
    			// now remove the clip or whatever you do to it
    			queueList[0].removeMovieClip();
    			// now shift the list to remove that first element
    			queueList.shift();
    			// alert the user it's done
    			alert.htmlText = "<font color='#0000FF'>Item </font><font color='#FF0000'>compiled. Moving on to next item.</font>";
    			// move all the items to the left
    			shift();
    		}
    	} else {
    		// text box just tells you what's going on
    		alert.htmlText = "<font color ='#0000FF'>Nothing</font> <font color='#FF0000'>to compile.</font><font color='#0000FF'>Click </font><font color='#FF0000'>to create items.</font>";
    	}
    }
    // run through the array of items and move them all over.
    //
    function shift() {
    	for (i=0; i<queueList.length; i++) {
    		queueList[i]._x = queueListCoords[i]._x;
    		queueList[i]._y = queueListCoords[i]._y;
    	}
    }



    Is this right so far? Seems to be stable testing it, only thing I need to fix now is the loading bar (i've removed the code just to make things easier). I'm guessing the answer is somewhere in // set compile time
    item.cTime = 30*obj.frame;
    ?

    I need to find a way to make the counter based off the animation, because I intend to add bevel effects to the bar .. or if theres an alternative way (like your previous method) you can think of which doesn't need the attach movie.

    Oh also I need to be able to change the loading time between each UNIT, so a blue energy ball might take 10 more seconds than a red ball. Is there a way to make the loading process unique to the item queued?

    Work in Progress so Far SWF

    http://www.liquid-visual.com/queueTest2.html

    I'm learning a lot from this!
    Last edited by Mitch Warren; 07-09-2007 at 04:33 AM.

  14. #14
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,379
    In the area where you have all you on releases, give obj the unique time (secondsYouWant * swfFrameRate). When you create the new item, just set cTime of the item to the time property of obj.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  15. #15
    Senior Designer
    Join Date
    Jul 2001
    Location
    Australia
    Posts
    367
    I'm sorry but I have no idea how to do that, I'm only a beginner at AS. Could you give me further instructions?

  16. #16
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,379
    Simply. The frame rate is how many frames go by each second, right? Since our system ticks away each frame, we've got to find common ground. In order to do this, we multiply how many seconds we want it to take to compile (maybe 10, as you said), and we multiply it by our frame rate (in my example, 31), so we get 310.

    Now that we know the time, we need to implement it. See the line var obj = newObj();, and how there's one in each of your buttons? Well right after the line obj.frame = someNumber, simply use the process above and write the time you want like this;
    obj.cTime = whateverYouWant.

    Finally, when you enqueue the item (and pass obj as a parameter) find the line that says item.cTime = 30*obj.frame and change it to item.cTime = obj.cTime.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  17. #17
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,379
    ignore this... stupid double post.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  18. #18
    Senior Designer
    Join Date
    Jul 2001
    Location
    Australia
    Posts
    367
    Brilliant! It works! This is like magic or something, cheers!

    http://www.liquid-visual.com/queueTest4.html

    In the latest version I've changed the times so each unit is slightly different. The last unit takes the longest to build.

    Still stuck on the load bar, not sure how to do that - is there a way to make the obj time govern the frames which progress in the compiler MC?

    Kind of like a preloader?

  19. #19
    Member
    Join Date
    Aug 2006
    Posts
    56
    The simplest method of achieving that, to my knowledge, would be to use the Tween class. If you're unfamiliar with it, then there's an excellent tutorial on it here: http://www.ksdd.com/articles/?p=108

  20. #20
    Senior Designer
    Join Date
    Jul 2001
    Location
    Australia
    Posts
    367
    A very interesting tutorial, some very good ideas there - but I don't think I can use the tween class in this case as I need to use the existing code to interact with the bar MC's frames, not only that, but I need to know WHERE in the code this can be implemented. I tried something like this, thinking it might work:

    Code:
    onEnterFrame = function () {
    	if (item.cTime != obj.cTime) {
    		compiler.nextFrame();
    	} else {
    		delete this.onEnterFrame;
    	}
    };
    But no cigar, it's more complicated than that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center