SamsonWasteCreative

Q: Dynamically change image upon shaking

Hi

 

I want to randomly pick one of 50 images and display it on the ad upon touching a button. This is the code that I have:

 

this.onViewControllerViewDidShake = function (event) {

   

    var total1 = 50;

    var index1 = Math.floor(Math.random() * total1) + 1;

   

    page.startActionList('image' + index1);

};

 

Instead of having to create 50 separate action lists, can I directly change the image in the code, without having to use action lists?

 

I have tried to change 'image.image.url'. But it does not work.

 

Thanks

Samson

iMac, OS X Yosemite (10.10.2)

Posted on Aug 12, 2015 9:45 AM

Close

Q: Dynamically change image upon shaking

  • All replies
  • Helpful answers

  • by msephton,

    msephton msephton Aug 27, 2015 10:09 AM in response to SamsonWasteCreative
    Level 1 (10 points)
    Aug 27, 2015 10:09 AM in response to SamsonWasteCreative

    You do it like this... I put this code on a button activation.

     

    var imageContainer = this.viewController.outlets.imageContainer;
      
    imageContainer.setImage(iAd.Image.imageForURL('assets/imageA.png'));
    
    
    

     

    imageContainer = an image object/container that has been added to the page.

    assets/imageA.png = an image that has been added to the assets panel.

     

    This method was easy enough to find:

     

    1. opening iAd Producer
    2. Help > Code Documentation
    3. search for "image class"
    4. choose iAd.Image Class
    5. read Creating Images > imageForURL

     

    Let me know how you get on!

     

    matt