A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Sending a Var outside of a MC to the root

  1. #1
    Member
    Join Date
    Aug 2006
    Posts
    63

    Sending a Var outside of a MC to the root

    Please help.

    I brought a pre-built shopping cart and I'm trying to put some buttons in another MC but when I click them the cart don't update.

    The original setup of the cart was:

    The 'Add to cart' buttons are on the root and the cart was inside an MC also on the root.

    Now I understand that it's not not working due to me moving the buttons into a MC.

    Can anyone tell me what I have to do to make this work so I can have my buttons inside a different MC

    This is the AS on the buttons originally:

    on (press)
    {
    var item = new CartItem

    ("Product 1", 10.00, 1);

    additem(item);
    }


    I tried putting the function for the button on the main stages but without any luck:

    pages.CarlsB.onRelease = function () {

    var item = new CartItem
    ("Product 1", 10.00, 1);
    additem(item);
    }

    I really hope someone can help.

    Many thanks,

    Stuart.

  2. #2
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554
    You added the CartItem to the root actions rather than the button actions. You need to put
    pages.CarlsB.item = new CartItem in that second piece of code if you want the CartItem object to be assigned to the button. I doubt that will fix the problem though, the code probably references that button in other locations as being at the root location... Give it a try but you might need to alter some other code.
    So tired of all the fighting....

    http://joejoe2288.kawanda.net

  3. #3
    Member
    Join Date
    Aug 2006
    Posts
    63
    Hi and thanks for the reply but, i'm not sure i understand fully. You say i've added the CartItem to the root. Do you mean i've put the function on the root instead of on the button itself?

    Many thanks.

  4. #4
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554
    Yea, thats what I meant, you added the declaration of the CartItem to the root, so you have to change your reference path to match where the button now resides.
    So tired of all the fighting....

    http://joejoe2288.kawanda.net

  5. #5
    Member
    Join Date
    Aug 2006
    Posts
    63
    Any ideas how i would change the code to acheive this?

  6. #6
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    try passing parameters to a function on the root timeline -

    PHP Code:
    pages.CarlsB.onRelease = function () {
    _root.myFunc("Product 1"10.001);
    }; 

    function 
    myFunc(a,b,c){
    item = new CartItem(a,b,c);
    additem(item);

    not tested...hth ??

  7. #7
    Member
    Join Date
    Aug 2006
    Posts
    63
    That didn't work but it thinks it's because I don't really know AS well enough

    is it best to have the AS on the root or on the buttons?

    I though it wouldn't be too hard to put it in a a function like I originally did and as dog suggested.

    Do i need to put a path on the Var item or new cart item - or the woud it be on the add item, and how would I do that exactly.

    pages.CarlsB.onRelease = function () {

    var item = new CartItem
    ("Product 1", 10.00, 1);
    additem(item);
    }


    sorry this is very lame, it's just i'm still learning and I realy need to get this done for a friend.

    Any help is much apreciated,

    Many thanks.

  8. #8

    var item at _root.

    just wondering if you found a fix for this as I have a similar problem. I need to have the variable for the shopping cart passed to the _root. of the movie..

    Any help would be great!!!

    Thanx in advance guys!

  9. #9
    Member
    Join Date
    Aug 2006
    Posts
    63
    Hi there,

    Yes, I did get it sorted. Here's how.

    My original problem was with this code sending the vars out of the MC to the root:

    on (press)
    {
    var item = new CartItem

    ("VK Blue Large Bottle", 4.00, 1);

    _parent.additem(item);
    }

    And I managed to get it to send the vars out to the root by using _parent. as shown below.

    on (press)
    {
    var item = new _parent.CartItem

    ("VK Blue Large Bottle", 4.00, 1);

    _parent.additem(item);
    }

    Hope this helps.

  10. #10

    Talking var item at _root.

    THANK YOU THANK YOU THANK YOU!!!! that has saved me so many headaches!
    you've really saved me some serious time here!.. so simple yet I would never had thought of it!

    Thanx again my friend!

    Monkai

  11. #11
    Member
    Join Date
    Aug 2006
    Posts
    63
    No worries.

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