A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: Create-than drag and drop at fixed location

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    8

    Post Create-than drag and drop at fixed location

    Hello there. I am quite new working with Flash. I have Flash Macromedia Professional 8 and I'd like to create something involving the drag and drop to snapping targets using a model I've find it very useful.
    I have only one problem: The example has only one button that spawn a single type of item. I'l like to have 2 more buttons that spawn another two different items. So I have made another 2 more buttons named ("Create Item 2" & "Create Item 3") at the bottom of the screen, and here is the problem: I don't know how to make them to create a different item every time each of them is pressed. I've tried several times modifying the main script but it appears I'm missing something important. In other words, I would like the script to be like this: When button "Create Item" is pressed, it generates an infinite number of "Item1" which can be dragged and snapped in the inventory; When "Create Item2" is pressed, it generates an infinite number of stickable "Item2" and the same with the third button, it creates a different Item to show up and dragged to the desired targets.
    If you really want to tell me how to do it, it would be great. I didn't count how much time I've spent to find an answer to this problem and I looked over the entire WWW to find a solution and simply there is not! I believe this is not something impossible to achieve, I mean....since it works to generate an item, this should work (at least theoretically) for an infinite number of other "Library" items.

    Once again, if any of you could give me a hint or advice to point me in the right direction, I would be sincerely greatful. Thank you all for your time.


    PS: I have attached the FLA file in case someone wants to take a look over my problem.
    Attached Files Attached Files

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Hi,

    you can't give all three buttons the same instance name, 'cause then Flash will only target one of them, which in this case is the first button! Give the other two a unique instance name, like click_item_btn2 and click_item_btn3, this is essential!

    and then simply copy and paste your first button's actionscript to the other two buttons, like this:

    Actionscript Code:
    create_item_btn2.onRelease = function()
    {
        createInventoryItem();
    }

    create_item_btn3.onRelease = function()
    {
        createInventoryItem();
    }
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    8

    drag and drop and snap

    Hi,

    I have uploaded the file with all the modifications you have told me about. I have renamed those 2 buttons and I also added the required actionscript to them in the main layer.
    Nothing happens, except this time those two buttons spawns the button nr. 1 tile over and over again....
    If you would like to talk over the file, make the required modifications there and than reupload it.....that would be more than welcomed!
    Attached Files Attached Files

  4. #4
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Oh, you want different item spawned for each button. Assuming you know how to give a Movieclip, a linkage name in the Library, give the two other Movieclips linkage names as well (right-click one at a time, press Linkage, tick Export for Actionscript and press OK, no need to change the name, as it's good as it is). Then, change your function createInventoryItem(), the whole function, to this:

    Actionscript Code:
    function createInventoryItem(itemName)
    {
        //attach item to stage
        var _item = attachMovie(itemName, "item"+uniqueItemId, _root.getNextHighestDepth());
       
        //set item position
        _item._x = 280;
        _item._y = 320;
       
        //set item settings
        _item.myName = "item"+uniqueItemId;
        _item.slotID = "empty";
       
        //make item a button
        _item.onPress = function()
        {
            dragItem(this)
        }
        _item.onRelease = _item.onReleaseOutside = function()
        {
            dropItem(this);
        }
       
        //add item to array
        items_array.push(_item);
       
        //update unique Item Id
        uniqueItemId++;
    }

    Now, you can pass arguments to it, to choose which item should be spawned to the stage. Next, change the last code, the one for the first button, to this:

    Actionscript Code:
    create_item_btn.onRelease = function()
    {
        createInventoryItem("item");
    }

    create_item_btn2.onRelease = function()
    {
        createInventoryItem("item2");
    }

    create_item_btn3.onRelease = function()
    {
        createInventoryItem("item3");
    }

    This will call the same function for each button, but with different arguments to spawn different items on the stage!

    Hope this works

    EDIT: 900th post
    Last edited by Nig 13; 01-21-2012 at 08:52 AM.
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  5. #5
    Junior Member
    Join Date
    Jan 2012
    Posts
    8

    The sight of miracles

    OH my GOD !!! It truly works!
    You are my hero!
    Since I couldn't find a solution to this problem on the entire web, I cannot express the feelings I have in this moment.
    Well...let me take a short break to recover my senses....

    ...

    Thank you!

  6. #6
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    haha, no problem
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  7. #7
    Junior Member
    Join Date
    Jan 2012
    Posts
    8

    close tile btn, delay effect or loading jpg's from an external source

    Hello again,

    Now, I have my prodject finished by 100%. Although I still have 3 minor questions that I would like to ask (and although they may not be answered due to the high difficulty level involved), I still consider the prodject done.

    1) Before having the option to turn the tiles into an endless spawning mode, in my old prodject, I ended up with ~ 200 tiles, each one draggable as a stad alone, but using a different action script, of course. There, I managed to insert little individual "tweeks" that worked so well along with that type of script. And I'm referring that each draggable tile was a movie script and had an option (a small "X" button attached to it), to close that tile at need.

    Eg: "function dragSetup(clip, targArray) {
    clip.onPress = function() {
    startDrag(this);
    if (this.closeMC.hitTest(_xmouse, _ymouse, true)) {
    this._visible = false;

    }"

    2) Also, the tile/s was forced to stick/return to their origins with some kind of "delay" effect which was pretty cool and now, I miss it somehow.

    Eg: "// then move the MC back to its original starting point (with a smooth motion)"
    if (!this.beingDragged && !this.onTarget) {
    this._x -= (this._x-this.myHomeX)/5;
    this._y -= (this._y-this.myHomeY)/5;"

    But the more important was the close tile button.
    Now, after a few attempts working with this new script, and some searches over the WWW, I have found out that I cannot add a close button to an already existent button, UNLESS I use some sort of trick, like this: over the main image, place a transparent button, than the close button goes on top of those two and in the final, select the all layers and made them a movie clip, etc. etc.
    After a few attempts I simply gave up, because with this script, the button (which was supposed to close the tile) was treated like a draggable thing too, and couldn't stand on top and doing it's closing function.

    3) The third problem is more like a personal wish. In this prodject I have 20 movie clips and I use them as backgrounds with a simple command like this:

    Eg: "vis();
    function vis(){
    _root.background0._visible=true;
    _root.background1._visible=false;
    _root.background2._visible=false;
    ----------------------------------
    _root.background20._visible=false;
    }"
    All is working fine in testing mode, but after I save the file and testing it in a browser, not only it's a waaaaay to large, but due to this it's get laggy, too.

    So, I decided to look for another trick to solve this.
    All I want is to make each of the 20 backgrounds "gostly" somehow (without weight) and keeping their actual position unchanged, to add/alter the code of the script in some way, when someone press for example the button nr. 7-to show bg. nr. 7, but the image that was initially taken from the main file itself, this time to be taken from the hosting server or from a collection of these bgs. I have on another hosting place.
    I am almost sure this can be achieved and I have found a script related to this:

    Eg: "background0.onRelease = function(){
    getURL("http://www.my place.com/........");
    }"

    If you are more familiar than me with this, maybe you can give me a little helpful hand, keeping in mind that I would like to preserve the actual position of the backgrounds, reducing them to almost "no weight", and on press (internet connection recquired), to show up from anywhere else, except from my flash file.
    I will be very pleased if someone will take a look over these and give me a glimpse or some sort of advice how to proceed or at least to tell which one is/may be achievable and which one is not.
    The prodject is ready without these, but if I can work around the solution, it would be a great addition to the file. I repeat, these little concernings are not a must and it's not a great, great loss if I don't include them.
    Anyway, thank you in advance for reading this message.

  8. #8
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Would you mind posting the FLA file ?
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  9. #9
    Junior Member
    Join Date
    Jan 2012
    Posts
    8

    Post drag, drop, snap and close

    Ok, are you still there?
    Here we go...take a look (sorry it took so long my response).

    1) Basically, what I try to achieve, is adding a close button over my spawning tiles. I have found a demo which apparently works, but not on a spawning....things. I have tried it, but I didn't achieve the desired results. I have inserted the original demo, too.
    Beside this, I have attached the other 2 files, the first one with my closing method (but without spawning mode), and the other one with the new script (in which you have helped me so much).

    2) The other issue, is on the background images. I have so many, that "eats" a lot of space after I save the final prodject. I would like to find a method, which empty-es the content of the bg's, and adding in the button script some sort of code who lead the action to a hosting place (outside of the file) from where the image loads itself, right in the place I put it in the prodject.

    3) The third one, is the least important, it adds a silky and cute delay at the moving tiles which makes them out of ordinary.

    Many, many, many thanks!!!
    Attached Files Attached Files

  10. #10
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    DOWNLOAD FIXED FLA FILE

    I've added the close button, and also fixed the error the smooth drag 'n' drop caused. To change the background, check the function on the background layer, loadImage. There's an example after the function, to demonstrate it. Simply use that code on one of your background buttons, and call that function with the URL path to the image you want as the background, and it will automatically load it in Flash and change its size to fit the screen!

    Hope this helps
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  11. #11
    Junior Member
    Join Date
    Jan 2012
    Posts
    8
    This is exactly what I was looking for!
    I have seen you had to rewrite the whole script in order to add that close button.
    So in Flash, for any small or big modification, the action script has to be re-written from the ground?
    Thank you again friend, for what you have done for me!
    -I owe you.-

  12. #12
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    No problem

    So in Flash, for any small or big modification, the action script has to be re-written from the ground?
    not necessarily, but it depends on what the context is. In this case, since the close button was becoming a part of the dragging, I had to separate it, so that the close button was clickable when pressing it, instead of dragging. I have a lot of experience in Flash and have developed a brain to think of other ways around certain problems, and hopefully you will as well if you keep practicing
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  13. #13
    Junior Member
    Join Date
    Jan 2012
    Posts
    8

    Thumbs up

    So, in other words: you have developed a way to take yourself/or someone you want out, from any possible situation?
    In this case, can I ask you if there's (still) something you cannot achieve with Flash? But other software can do the job very well? Just curious.
    It looks like GOD-that created everything from scratch (from nothing), you can also create everything....from Flash! Which is marvelous!


    PS: MIRACULOUS!!!

    Quote Originally Posted by Nig 13 View Post
    ... and hopefully you will as well if you keep practicing
    Yap, thanks for the wish. But I'll stick with what I have in this moment. Everyone has ambitions, goals to achieve in life. You have helped me, now it's my time to help others with the aplication/s I created. We created I mean.
    If I continue to sink myself further into Flash, I'll have no time to do other things which are important, too.
    For example if anyone would know Flash, there will be no one who take care of the automobile industry, or grocery, pharmacy, bread and so on. You got the idea. Everyone has his/her place in life in which to succeed. That's why we should respect anyone for what he/she does. Bec, we don't have all the time in the world to do/perform whatever we want.

    See you.

  14. #14
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    true

    and I've done so much Flash that actionscript has been implemented in my mindset, so I always think about everything, almost everything, in a Flash-related way :P
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  15. #15
    Junior Member
    Join Date
    Jan 2012
    Posts
    8

    long time no see...

    Hello, Nig 13!
    Right now, I'm confronting with a new thing wich is a little bit complicate for my understanding, but I hope you know the mechanics behind it's working.

    There are 3 main buttons aligned horizontally: GROUP 1, GROUP 2 and GROUP 3.

    If you press the first button (GROUP 1), it reveals other buttons.
    - All these buttons have an image associated with them (when mouse enter the button area, the image is loaded from an external source into the movie frame);
    - Each button spawn a unique item at a spawning place;
    - The items has the same property as their trigger button, showing the same image loaded into the background_mc;
    - Spawned items can be draggable to the marked area on the right and snap into any place in a slow motion;
    - After the item snapped into position, it can be picked and moved freely onto the other droppables and so on;
    - If you pick up the item and move it outside the snapping area, doesn't return to its original spawning point but stays in place;
    - Each item has a close button on it;
    - Each item plays its own sound at a "on release" pressing;

    - There is a button on the stage which turns on/off all the sounds the items make when they are released. This button starts with all the sounds muted at the loading screen;

    =========================================

    If you press the second button (GROUP 2), it reveals another set of buttons and closes the ones from the other groups (GROUP 1 and GROUP 3);

    - All the items that was dragged out from the initial spawning place should remain into their position (snapped or outside of the droppable region), only the buttons associated with the other groups to disappear;

    =========================================

    If the third button should be pressed (GROUP 3), the buttons from the GROUP 1 and GROUP 3 will disappear, and another set of buttons come into place;

    - With other words, at any of the group button pressing, that means to show up its corresponding set of buttons and close the ones from the previous groups which was opened, ignoring the items which was selected out from their sets.

    And now, the awesome thing: I have done all of this above if you can believe it (and only God saw me), EXCEPT the following facts:
    - The buttons associated with the groups are the items themselves (and don't spawn at a desirable place like they should) and can be dragged, so...
    - I cannot separate the items that was removed from their groups. I mean, when I press any of the 3 group buttons, it disappear ALL of the items, not only the ones which was not choosed from their group;
    - I couldn't attach a close button on top of them;
    - I couldn't attach a uniquie sound at the item release.

    I have tried several coding methods, but I sticked to the one which was closer to my need. And yes, I have spent a lot of time to have this all above....which are almost useless in this form, btw.

    I have attached 2 files: the initial file I have worked upon it from the beginning, and the one based on your example posted above. Look over your file, 'cause it has more finished things, and try to add at it if you can the loading image and sound over the movable items, the mute button and the non sticky option when out of the droppable zone.

    I must say that in the end, each group will have ~ 80 buttons, and there will be 12 groups in total on a page.
    Let me know please, if you have a little bit of time to look over this.

    10q


    PS: Whether your response is an Yes or a No, you should also check your pay-pal account. A "thank you" reward will be available at the beginning of the next week. Yeah, I know you'll gonna say smth. like..."You don't have to!" or things like this. Well....I don't care. Because by being so kind, you have earned over time, your rights to be treated with respect.
    Attached Files Attached Files

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